[ansible-project] Re: New to ansible -- Looping through files with wildcards

2017-08-11 Thread John Harmon
Forgive me for responding to myself... I just hope that someone in the 
future might find this relevant/useful.

added "changed_when: false" to the shell task.  That took care of the 
idempotent issue I was seeing by overriding the change result.

Still plugging away on the other issue

- name: Disabling NetworkManager in ifcfg-* files
  lineinfile:
path: /etc/sysconfig/network-scripts/{{path_files.stdout_lines}}
regexp: '^NM_CONTROLLED'
line: "NM_CONTROLLED=no"

The above is now returning:
TASK [dns_update : Disabling NetworkManager in ifcfg-* files] 

fatal: [ansibletest-rhel7]: FAILED! => {"changed": false, "failed": true, 
"msg": "Destination /etc/sysconfig/network-scripts/[u'ifcfg-bond0', 
u'ifcfg-eth0', u'ifcfg-eth1', u'ifcfg-eth2', u'ifcfg-eth3', u'ifcfg-eth4', 
u'ifcfg-eth5', u'ifcfg-lo'] does not exist !", "rc": 257}
fatal: [ansibletest-rhel6]: FAILED! => {"changed": false, "failed": true, 
"msg": "Destination /etc/sysconfig/network-scripts/[u'ifcfg-bond0', 
u'ifcfg-eth0', u'ifcfg-eth1', u'ifcfg-eth2', u'ifcfg-eth3', u'ifcfg-eth4', 
u'ifcfg-eth5', u'ifcfg-lo'] does not exist !", "rc": 257}
fatal: [ansibletest-oel6]: FAILED! => {"changed": false, "failed": true, 
"msg": "Destination /etc/sysconfig/network-scripts/[u'ifcfg-bond0', 
u'ifcfg-eth0', u'ifcfg-eth1', u'ifcfg-eth2', u'ifcfg-eth3', u'ifcfg-eth4', 
u'ifcfg-eth5', u'ifcfg-lo'] does not exist !", "rc": 257}

Notice the ifcfg* names are messed up.  I am trying to narrow down the 
reason

-- 
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/e77a3ea6-5cc6-442e-812e-46fc7ad2bdb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: New to ansible -- Looping through files with wildcards

2017-08-11 Thread Kai Stian Olstad

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.


[ansible-project] Re: New to ansible -- Looping through files with wildcards

2017-08-11 Thread John Harmon
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=3changed=1unreachable=0failed=0
ansibletest-rhel6  : ok=3changed=1unreachable=0failed=0
ansibletest-rhel7  : ok=3changed=1unreachable=0failed=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 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/ca145f16-714b-48d4-a69f-3ac7f079bb18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.