Trying this (which doesn't delete the lines yet).... but the other problem
is that the shell task is not idempotent
---
# 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
- 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 }}"
--------------------RESULTS------------------------
PLAY [test]
******************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts]
*******************************************************************************************************************************************************************************************************************
ok: [ansibletest-rhel7]
ok: [ansibletest-rhel6]
ok: [ansibletest-oel6]
TASK [dns_update : Retrieve ifcfg files in /etc/sysconfig/network-scripts]
***************************************************************************************************************************************************************
changed: [ansibletest-rhel7]
changed: [ansibletest-rhel6]
changed: [ansibletest-oel6]
TASK [dns_update : Removing all DNS entries in ifcfg-* files]
****************************************************************************************************************************************************************************
ok: [ansibletest-rhel7] => (item=ifcfg-bond0)
ok: [ansibletest-rhel6] => (item=ifcfg-bond0)
ok: [ansibletest-oel6] => (item=ifcfg-bond0)
ok: [ansibletest-rhel7] => (item=ifcfg-eth0)
ok: [ansibletest-rhel6] => (item=ifcfg-eth0)
ok: [ansibletest-oel6] => (item=ifcfg-eth0)
ok: [ansibletest-rhel7] => (item=ifcfg-eth1)
ok: [ansibletest-rhel6] => (item=ifcfg-eth1)
ok: [ansibletest-rhel7] => (item=ifcfg-eth2)
ok: [ansibletest-oel6] => (item=ifcfg-eth1)
ok: [ansibletest-rhel6] => (item=ifcfg-eth2)
ok: [ansibletest-rhel7] => (item=ifcfg-eth3)
ok: [ansibletest-oel6] => (item=ifcfg-eth2)
ok: [ansibletest-rhel7] => (item=ifcfg-eth4)
ok: [ansibletest-rhel6] => (item=ifcfg-eth3)
ok: [ansibletest-rhel7] => (item=ifcfg-eth5)
ok: [ansibletest-oel6] => (item=ifcfg-eth3)
ok: [ansibletest-rhel6] => (item=ifcfg-eth4)
ok: [ansibletest-rhel7] => (item=ifcfg-lo)
ok: [ansibletest-rhel6] => (item=ifcfg-eth5)
ok: [ansibletest-oel6] => (item=ifcfg-eth4)
ok: [ansibletest-rhel6] => (item=ifcfg-lo)
ok: [ansibletest-oel6] => (item=ifcfg-eth5)
ok: [ansibletest-oel6] => (item=ifcfg-lo)
PLAY RECAP
*******************************************************************************************************************************************************************************************************************************
ansibletest-oel6 : ok=3 changed=1 unreachable=0 failed=0
ansibletest-rhel6 : ok=3 changed=1 unreachable=0 failed=0
ansibletest-rhel7 : ok=3 changed=1 unreachable=0 failed=0
--
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/ca145f16-714b-48d4-a69f-3ac7f079bb18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.