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