'Fixed sorting order of hosts in inventory_hostname groups

I am using AWX with the combination of CMDB inventory and many groups are defined there . i.e. from set_A to set_Z and blah blah blah

I am calling many groups in my Playbook i.e. 'set_A, set_B, set_C, set_D' and hosts exist in each group.

host9 is in set_C inventory group host1 and 3 is in set_B inventory group host7 is in set_A inventory group

When I am calling below it's giving me bunch of warning messages but it's doing the Job.

"[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: inventory_hostname in groups[
"{{item}}" ]

My syntax is:
    inventory_hostname in groups[ "{{item}}" ] 
        with_items:
          - 'set_A'
          - 'set_B'
          - 'set_C'
          - 'set_D'

Is there a better way of doing this? Also on each run playbook is randomizing sorting order each time. i.e. picking up hosts in set_B first then set_A then set_C.

What I want is that: Group order must be strictly followed if hosts exist:

  • If hosts exist in set_A then it MUST run first, then hosts in set_B then hosts in set_C and so on and so forth. For some reason sorting order is shuffling each time.

Is there a way that sorting order can be fixed/ or same each time? host sorting order is not important but the group sorting order is.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source