I have been working on this for days. I don't mind because I am learning a ton of stuff (as I am new to ansible), but the only way I can get this to work properly is to use a shell: module (utilizing sed). I would prefer to avoid that if I can.
Tasks:
Gather list of ifcfg-* files (except ifcfg-lo)
Add DNS entries if missing; otherwise replace DNS entries if they don't match <string1> or <string2>- name: Gather list of ifcfg-* files
shell: ls "{{ net_path }}" | grep ^ifcfg- | grep -ve ifcfg-lo -e \@ # \@ excludes ansible backup files
register: ifcfg_list
changed_when: false
The above works fine... it is the second task that is getting me.
Using the above I have tried all sorts of things. I have learned that lineinfile regexp only matches the last found match, replace matches all. blockinfile also appears to only to affect the last found match.
Anyway, how would you approach this without shell:?
As an example:
I wish to use the following vars as my dns entries:
dns1=10.10.10.10
dns2=20.20.20.20
ifcfg-eth0 contains:
DNS1=1.2.3.4
DNS2=2.3.4.5
ifcfg-eth1 doesn't contain any dns entries