On 11. aug. 2017 22:59, John Harmon wrote:
Trying this (which doesn't delete the lines yet).... but the other problem
is that the shell task is not idempotent


What do you mean by "is not idempotent" it's just listing files and it need to do that every time.


---
# tasks file for dns_update
- name: Retrieve ifcfg files in /etc/sysconfig/network-scripts
   shell:  ls /etc/sysconfig/network-scripts | grep ^ifcfg-
   register: path_files

Alternative is the find module
- name: Retrieve ifcfg files in /etc/sysconfig/network-scripts
  find:
    paths: ls /etc/sysconfig/network-scripts
    pattern: ifcfg-*
  register: path_files


- name: Removing all DNS entries in ifcfg-* files
   lineinfile:
     path: /etc/sysconfig/network-scripts/{{ path_files.stdout_lines }}
     state: absent
     regexp: '^DNS'
   with_items: "{{ path_files.stdout_lines }}"

The value from with_items i in a variable called item so the path sould be
  path: /etc/sysconfig/network-scripts/{{ item }}


With the find module above this task should look like this
- name: Removing all DNS entries in ifcfg-* files
   lineinfile:
     path: '{{ item.path }}'
     state: absent
     regexp: '^DNS'
   with_items: '{{ path_files.files }}'


--
Kai Stian Olstad

--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/12bf9e46-a6f2-f905-eb0a-7557c0486c9c%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to