I have the following, and wish to combine them, but don't know how because 
my with_items is referencing a variable.  Wondering if someone can guide me 
(if possible) on how to combine these two stanzas:

- name: Add DNS1 to ifcfg-* files if missing
  lineinfile:
    path: "{{ net_path }}{{ item }}"
    state: present
    regexp: "^DNS1"
    line: "DNS1={{ dns1 }}"
  with_items: "{{ ifcfg_list.stdout_lines }}"
  ignore_errors: yes
  notify:
    - Networking

- name: Add DNS2 to ifcfg-* files if missing
  lineinfile:
    path: "{{ net_path }}{{ item }}"
    state: present
    regexp: "^DNS2"
    line: "DNS2={{ dns2 }}"
  with_items: "{{ ifcfg_list.stdout_lines }}"
  ignore_errors: yes
  notify:
    - Networking

Here is how far I get:

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

-- 
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/1c9a9ac8-9382-4974-a47a-78106cd355c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to