Skip to content
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

The order of the hosts in a group_by updated group is not guaranteed to be the same between runs #16933

Closed
srgvg opened this issue Aug 3, 2016 · 10 comments
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@srgvg
Copy link
Contributor

srgvg commented Aug 3, 2016

ISSUE TYPE
  • Bug Report
COMPONENT NAME

core

ANSIBLE VERSION
2.1.0.0
SUMMARY

The order of the hosts in a group_by updated group is not guaranteed to be the same between runs.

Adding a serial: 1 in the play where group_by is done seems to be a workaround

STEPS TO REPRODUCE

Just do a group_by, and do repeated runs, and debug check the order of the nodes in the created/updated group.

Running from a pure hosts based inventory or from a dirctory based inventory might trigger a difference sooner.

EXPECTED RESULTS

The same order at every run, alfanumerically, in the same order as the hosts were already in other groups.

ACTUAL RESULTS

Sometimes a reversed order.

@jctanner
Copy link
Contributor

jctanner commented Aug 5, 2016

@srvg per our irc convo, would be nice to have a simple reproducer to demonstrate the issue.

@jctanner jctanner added bug_report needs_info This issue requires further information. Please answer any outstanding questions. labels Aug 5, 2016
@srgvg
Copy link
Contributor Author

srgvg commented Aug 5, 2016

@jctanner jctanner removed the needs_info This issue requires further information. Please answer any outstanding questions. label Aug 5, 2016
@ansibot ansibot added the affects_2.1 This issue/PR affects Ansible v2.1 label Sep 8, 2016
@ansibot ansibot added needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. and removed needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels Mar 29, 2017
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@gundalow
Copy link
Contributor

@srgvg Repoducer no longer exists :(

@gundalow
Copy link
Contributor

We are considering using ordereddict in the future which should solve this

@srgvg
Copy link
Contributor Author

srgvg commented Feb 22, 2019

@gundalow Sorry, I changed my github username a while ago! srvg -> srgvg

Reproducer:

https://gist.github.com/srgvg/bbc05198f033337cbb4b599c13839092

@gundalow gundalow reopened this Feb 22, 2019
@jd3shaw
Copy link

jd3shaw commented May 11, 2020

I am also experiencing this issue. Random changing the order of groups and serial plays later on running out of order. Is there any solution other than running my group_by add play in serial as well (this greatly increase my runtime and I would like to avoid it). I think I found another work around which doesn't involve running an entire play as serial:1
[inventorygroup-ordered]
host1
host2
host3

-group_by add install
host1
host3
host2
(I've noticed this only happens occasionally and not with a low number of hosts)

install group:
hosts: inventorygroup-ordered:&install
^:fingers crossed: takes the order of the original inventory group but only includes servers in the install group

@bcoca
Copy link
Member

bcoca commented May 11, 2020

probably fixed via #58000, please confirm

long explanation: python 'mapping order' is inconsistent across runs/versions of Python, it depends on the hashing done, the PR above forces to always uses 'ordered dictionaries' , which is also the default in newer versions of Python (language in which Ansible is written).

@jd3shaw
Copy link

jd3shaw commented May 11, 2020

Thanks @bcoca I'll try and upgrade the Ansible version I'm running asap.

@jd3shaw
Copy link

jd3shaw commented May 15, 2020

Just FYI @bcoca It seems like my work around works.
I have an example of 5 hosts where 2 were swapped in the order (group_by install added) then a later play using inventorygroup-ordered:&install restored the original order. I'll probably leave it here as we're not likely to upgrade our Ansible docker until these changes are in stable.
Any idea how I can watch a merge for when it goes into a stable release?

@ansibot ansibot added the needs_triage Needs a first human triage before being processed. label May 15, 2020
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label May 18, 2020
@bcoca
Copy link
Member

bcoca commented Jun 3, 2020

it was already merged, will be in released in 2.10, so I'm closing this issue as resolved.

@bcoca bcoca closed this as completed Jun 3, 2020
@ansible ansible locked and limited conversation to collaborators Jul 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

7 participants