Hi,
Many thanks for that, hoped it was straight forward.
All working now.
Many thanks,
Jon
On Wednesday, 16 November 2016 17:06:47 UTC, Jon Kent wrote:
>
> Hi,
>
> I've been trying to get Ansible Tower to run a playbook/role which should
> update the /etc/hosts file across all hosts in a group.
>
> I have the following playbook:
>
> - name: Update hosts file if required
> hosts: all
> gather_facts: yes
>
> roles:
> - { role: hostfile }
>
> and the following role:
>
> ---
>
> - debug: var=ansible_default_ipv4.address
>
> - name: node to ip mapping
> debug: var=hostvars[item].ansible_default_ipv4.address
> with_items: groups['all']
>
> - name: Build Host file
> lineinfile: dest=/etc/hosts
> regex='.*{{ item }}$ }}'
> line="{{ hostvars[item].ansible_default_ipv4.address }}
> {{item}}"
> state=present
> when: hostvars[item].ansible_default_ipv4.address is defined
> with_items: groups['all']
> become: true
>
> However, when Tower run this its skips the 2 hosts in the group. From
> looking at the debug output it would appear that Tower is not caching the
> facts under hostvars as you can see from the output below:
>
> TASK [setup]
> ******************************************************************* ok:
> [172.31.9.43] ok: [52.50.60.2] TASK [hostfile : debug]
> ******************************************************** ok:
> [172.31.9.43] => { "ansible_default_ipv4.address": "172.31.9.43" } ok:
> [52.50.60.2] => { "ansible_default_ipv4.address": "172.31.33.206" } TASK
> [hostfile : node to ip mapping] *******************************************
> ok:
> [172.31.9.43] => (item=groups['all']) => {
> "hostvars[item].ansible_default_ipv4.address": "VARIABLE IS NOT DEFINED!",
> "item": "groups['all']" } ok: [52.50.60.2] => (item=groups['all']) => {
> "hostvars[item].ansible_default_ipv4.address": "VARIABLE IS NOT DEFINED!",
> "item": "groups['all']" } TASK [hostfile : Build Host file]
> ********************************************** skipping: [172.31.9.43] =>
> (item=groups['all']) skipping: [52.50.60.2] => (item=groups['all']) PLAY
> RECAP *********************************************************************
> 172.31.9.43 : ok=3 changed=0 unreachable=0 failed=0 52.50.60.2 : ok=3
> changed=0
> unreachable=0 failed=0
>
>
> I have a feeling that I'm missing something very obvious here. Any ideas
> where I should look?
>
> Thanks,
> Jon
>
>
>
>
--
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/e91ef3d5-6b13-4eaa-9635-226d4d83e0e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.