New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Host order in groups variable is not 'as provided' when using yaml inventory #34861
Comments
@YoninL Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. Here are the items we could not find in your description:
Please set the description of this issue with this template: |
I've update the title, to better reflect the issue. Based on what I have read in this issue, it appears as though the issue is that the host order in the When using a YAML inventory, the host order in the |
thanks @sivel , you may say the host order is not consistent in ini inventory, but I want the order in yaml inventory matters/'as provided' just like ini inventory, otherwise I don't know which one should be first, which one should be second before test. |
Ok, that makes a little more sense then. I was having difficulty following your description of the problem. Roughly, I know how this needs to be handled, or at minimum what the problem is. In python a dict is not ordered, as compared to a list which is ordered. So when loading any inventory source that represents the hosts as keys in a dictionary, it is likely that order will not be maintained, or at minimum we can say that the order is not guaranteed. We could use something like I'm hesitant to optionally use There is a compatible But since we just need to go back to 2.6, it might be easier to modify and vendor what lives in 2.7, but we will have to evaluate this. |
First stab at |
not a fix that will be going in but #36644 'fixes' this issue, a similar approach just for the yaml inventory plugin might be a solution |
hi @sivel. As Ansible 2.7 will require Python 2.7+ on the controller machine, is it an option to revive your idea of using an OrderedDict? |
@bcoca please up this issue. We think order of the play hosts must to be by order in inventory without get some host for first to play from some host id in group. Sometimes ansible get host id 0 sometimes get for first to run last host in group, its not normal behaviour if deploy start on random host on group. We want have one stable behaviour for run. |
@westsouthnight it is being worked on, but the problem is not limited to the YAML plugin as restructuring of how groups are calculated to increase performance removed the ordering, so several cascading fixes have to take place. As a workaround you can use the |
@bcoca Thanks! We really awaiting this! |
Updated |
The same issue here.
When I try to use I found a workaround for this. The first task in my ansible role is
Then I don't use |
This issue resolved on ansible 2.9.5 + python 3.6.9. I have same issue on ansible 2.9.5 + python 3.5.2. |
@rony36 any Ansible version with python >=3.6 won't have the issue because Python changed to preserve order in dictionaries, lower versions of Python have either a 'hash order' or even a 'randomized order' to prevent predictability. Going forward this will now work independent of Python versions via #58000. |
ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
OS / ENVIRONMENT
SUMMARY
The order of elements in hostvars[groups['group_name']] list doesn't follow the order in yaml format host inventory file.
Host file:
Commands run against the host file:
EXPECTED RESULTS
192.168.11.1
ACTUAL RESULTS
192.168.11.2
STEPS TO REPRODUCE
Let's say we have two host files, host.yaml and host.ini.
host.yaml:
host.ini:
I want to run
ansible -i host.yaml localhost -m debug -a "var=hostvars[groups['mysql'][0]]"
to get the first host, but got the second one.While
ansible -i host.ini localhost -m debug -a "var=hostvars[groups['mysql'][0]]"
gives me correct result.You can see the order in host.ini matters, but in host.yaml not.
I need to use yaml format to store some variables which is encrypted by Ansible vault.
The text was updated successfully, but these errors were encountered: