I just posted my question on stackoverflow. Figured I will post here as well in hopes someone here can help.
http://stackoverflow.com/questions/43683862/lineinfile-ansible-module-skips-a-line *content:* I have a need to know the index of host names in the inventory. I am using the below code to create a variable file that I can use in a subsequent play book - name: Debug me hosts: hosts tasks: - debug: msg="{{ inventory_hostname }}" - debug: msg="{{ play_hosts.index(inventory_hostname) }}" - local_action: 'lineinfile create=yes dest=/tmp/test.conf line="host{{ play_hosts.index(inventory_hostname) }}= {{ inventory_hostname }}"' I have the following inventory file [hosts] my.host1.com my.host2.com Now when I run this, the test.conf that gets generated under /tmp sometimes has both hostnames like this host1= my.host2.com host0= my.host1.com when I run the same playbook a few times each time emptying the test.conf before running. quite a few times the file only has one entry host1= my.host2.com or host0= my.host1.com how come the same ansible playbook behaving differently? Please help. As you probably can already tell, I am new to ansible and trying from different examples that I have found online. -- 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/6b120267-bcfb-4733-b2f6-1e16084cb6d1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
