shell - Grep vars from a file with ansible to use later in a task with a for loop -


i relatively new ansible.

i have parameters.yml this:

parameters:    stuff: bullshit   otherstuff: otherbullshit   domain_locale: domain.locale.test   domain_differentlocale1: domain.differentlocale1.test   domain_differentlocale2: domain.differentlocale2.test   domain_differentlocale3: domain.differentlocale3.test   uninteresting_stuff: uninteresting_bullshit 

this file in directory, symlink in defaults/main.yml. doesn't matter.

what accomplish grep somehow within ansible task these domain.*.test values , use vars in task ansible. other task write directly after 127.0.0.1 localhost in same line in /etc/hosts.

i not sure of modules use in ansible. include_vars has no additional grep see it. set_fact not read different file(can combine shell command? how?). lineinfile not have source , dest, limited 1 file.

i thought post me: ansible read multiple variables same name vars_file not need grep part, need.

here go:

--- - hosts: localhost   gather_facts: no   vars:     parameters:       stuff: bullshit       otherstuff: otherbullshit       domain_locale: domain.locale.test       domain_differentlocale1: domain.differentlocale1.test       domain_differentlocale2: domain.differentlocale2.test       domain_differentlocale3: domain.differentlocale3.test       uninteresting_stuff: uninteresting_bullshit   tasks:     - lineinfile:         dest: /tmp/test.txt         regexp: ^127.0.0.1         line: "127.0.0.1 localhost {{ parameters.values() | select('match','domain.*test') | list | join(' ') }}" 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -