ansible tower messing up the order in which inventory hosts gets played

13 views
Skip to first unread message

madhan dhanikachalam

unread,
Nov 21, 2019, 8:36:38 AM11/21/19
to Ansible Development
i have a code like this

    - template:
        src: ../files/kfhost.j2
        dest: /app/bin/kafka/server.properties
        owner: kafka
        group: kafka
        mode: 0755

the jinga file has an entry like this

broker.id={{ play_hosts.index(inventory_hostname)+1 }}

when i have an inventory file like this

[all]
server1
server2
server3

and run this playbook from command line. server1 broker.id is set to 1, server2 broker.id is set to 2 and server3 broker.id is set to 3. 

when i run the same in ansbile tower, sometimes the server1 gets value 2, server2 gets value 1 

the order is getting mismatched.

just fyi there are other tasks before this task in the playbook 

any idea as to why this might be happening in tower and never when i run ansible-playbook command line



Tom Davison

unread,
Nov 21, 2019, 8:43:17 AM11/21/19
to madhan dhanikachalam, Ansible Development
My first thought is how do you have your inventory in tower? Does it match the same exact layout as your inventory on the command line?

As in server1 is the first entry, server2 the second, etc..?

But generally speaking, since inventories may not always be perfectly matched, a better solution would be to do some python/jinja2 logic in your Template to scan the inventory provided and generate the server properties.

--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/4b271314-1da7-4750-828e-42d4876d33aa%40googlegroups.com.

Nathan Brady

unread,
Nov 21, 2019, 9:43:14 AM11/21/19
to Tom Davison, madhan dhanikachalam, Ansible Development
You may want to try specifying the ordered at the playbook level.  You can find that option in the docs.


Nathan Brady
Red Hat Consulting


Alan Rominger

unread,
Nov 21, 2019, 10:38:09 AM11/21/19
to Tom Davison, madhan dhanikachalam, Ansible Development
Tower saves the inventory in the database that it gets from the ansible-inventory command. To the best of my memory, ansible-inventory does an ordered JSON dump. We later take it back out of the database for the job run (at which point I really don't think the JSON dump is ordered), the ordering is lost at some point along the line. Exactly where, and if it's one step or multiple steps, I don't know. We would need to maintain an order field in some shape or form to actually support it, and that's pretty non-trivial.

This is basically a known issue via https://github.com/ansible/awx/issues/2240

Alan
github: AlanCoding


On Thu, Nov 21, 2019 at 8:43 AM Tom Davison <tntda...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages