You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
The problem occurs on 2.2 but not on 2.1
A test case was created containing the following statement:
debug: var=groups['mygroup1']|list
If dynamic host group "mygroup1" created in a previous playbook by the group_by module contains four hosts, four hosts are output by the debug statement. If "mygroup1" contains eight hosts, only the first host is output by the debug statement most of the time but sometimes the second host is output. This is an intermittent problem. The problem does not occur when the host group contains 3 or 4 hosts but always occurs when the group contains 7 or 8 hosts.
STEPS TO REPRODUCE
name: Populate host group with host names
hosts: host1:host2:host3:host4
hosts: host1:host2:host3:host4:host5:host6:host7:host8
gather_facts: no
tasks:
name: task1
group_by: key='mygroup1'
name: Run playbook on all hosts in host group "mygroup1"
hosts: mygroup1
gather_facts: no
tasks:
name: task1
debug: var=inventory_hostname
name: Show hosts in host group "mygroup1"
hosts: localhost
gather_facts: no
tasks:
Since upgrading from Ansible 2.1 to 2.2, several playbooks that use the "group_by" module do not produce the correct results because variable substitution using the dynamic host group does not result in a complete list of hostnames. Most of the time, ansible only produces output for the first host in the host group and ignores the rest of the hosts. When using jinja2 filters as in the following example, ansible only processes the first host in dynamic host group x created by the group_by module:
{{ groups['x']|list }}
Note that the bug does not occur if the dynamic host group contains a small number of hosts e.g. 2, 3 or 4 hosts. The bug occurs when the dynamic host group contains a larger number of hosts e.g. 7, 8 or 9 hosts.
Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo.
A workaround is to use the add_host module rather than the group_by module (broken in Ansible 2.2) to create a dynamic adhoc host group. The playbook worked correctly after the following line:
ISSUE TYPE
COMPONENT NAME
group_by
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
SUMMARY
The problem occurs on 2.2 but not on 2.1
A test case was created containing the following statement:
debug: var=groups['mygroup1']|list
If dynamic host group "mygroup1" created in a previous playbook by the group_by module contains four hosts, four hosts are output by the debug statement. If "mygroup1" contains eight hosts, only the first host is output by the debug statement most of the time but sometimes the second host is output. This is an intermittent problem. The problem does not occur when the host group contains 3 or 4 hosts but always occurs when the group contains 7 or 8 hosts.
STEPS TO REPRODUCE
hosts: host1:host2:host3:host4
hosts: host1:host2:host3:host4:host5:host6:host7:host8
gather_facts: no
tasks:
name: task1
group_by: key='mygroup1'
name: Run playbook on all hosts in host group "mygroup1"
hosts: mygroup1
gather_facts: no
tasks:
debug: var=inventory_hostname
name: Show hosts in host group "mygroup1"
hosts: localhost
gather_facts: no
tasks:
debug: var=groups['mygroup1']|list
EXPECTED RESULTS
TASK [task1] *******************************************************************
ok: [localhost] => {
"groups['mygroup1']|list": [
"host1",
"host2",
"host3",
"host4",
"host5",
"host6",
"host7",
"host8",
]
}
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: