On Thursday, January 25, 2018 at 12:26:40 PM UTC-7, Kai Stian Olstad wrote:
>
> On Thursday, 25 January 2018 18.38.36 CET John Harmon wrote: 
> > How do I incorporate: 
> > "{{ ifcfg_list.stdout_lines }}" 
> > 
> > That allows me to loop through all ifcfg-* files (except ifcfg-lo) 
> > 
> > - name: Add DNS to ifcfg-* files if missing 
> >   lineinfile: 
> >     path: "{{ net_path }}{{ item.nic }}" #<--- This item is no longer 
> > reference by ifcfg_list.stdout_lines 
> >     state: present 
> >     regexp: "{{ item.regexp }}" 
> >     line: "{{ item.line }}" 
> >   with_items: 
> >     - {regexp: "^DNS1", line: "DNS1={{ dns1 }}", nic: 
> > "ifcfg_list.stdout_lines"} #<--- The nic section of these looks 
> incorrect 
> > to me, and I doubt it would work 
> >     - {regexp: "^DNS2", line: "DNS2={{ dns2 }}", nic: 
> > "ifcfg_list.stdout_lines"} 
> >   ignore_errors: yes 
> >   notify: 
> >     - Networking 
>
> Use the find module to search for the files and exclude the ifcfg-lo and 
> register the result. 
>
> Then you can use the with_nested in the lineinfile. 
>
>
> -- 
> Kai Stian Olstad 
>

I tried the following, but it failed.  Likely some syntax issues (doesn't 
like my var).  I am having a hard time finding comprehensive docs on 
with_nested.  I will keep trying, but if you have some suggestions, I am 
all ears.

- name: Add DNS entries to ifcfg-* files if missing
  lineinfile:
    path: "{{ net_path }}{{ item[0] }}"
    state: present
    regexp: "{{ item[1] }}"
    line: "{{ item[2] }}"
  with_nested:
    - ifcfg_list.stdout_lines
    - [ '^DNS1', '^DNS2' ]
    - [ 'DNS1={{ dns1 }}', 'DNS2={{ dns2 }}' ]

Failed message:
failed: [ansible-oel6] (item=[u'ifcfg_list.stdout_lines', u'^DNS1', u
'DNS1=10.253.1.23']) => {"changed": false, "item": [
"ifcfg_list.stdout_lines", "^DNS1", "DNS1=10.253.1.23"], "msg": "Destination 
/etc/sysconfig/network-scripts/ifcfg_list.stdout_lines does not exist !", 
"rc": 257}


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6867ac98-91c1-40a6-a7f8-733793caa686%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to