Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

ansible-2.2.0.0 group_by intermittent bug #5778

Closed
stanrate opened this issue Nov 30, 2016 · 5 comments
Closed

ansible-2.2.0.0 group_by intermittent bug #5778

stanrate opened this issue Nov 30, 2016 · 5 comments

Comments

@stanrate
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

group_by

ANSIBLE VERSION
ansible 2.2.0.0
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
  • 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:

    • name: task1
      debug: var=groups['mygroup1']|list
EXPECTED RESULTS

TASK [task1] *******************************************************************
ok: [localhost] => {
"groups['mygroup1']|list": [
"host1",
"host2",
"host3",
"host4",
"host5",
"host6",
"host7",
"host8",
]
}

ACTUAL RESULTS
TASK [task1] *******************************************************************
ok: [localhost] => {
    "groups['mygroup1']|list": [
        "host1", 
    ]
}
@stanrate
Copy link
Author

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.

@ansibot
Copy link

ansibot commented Nov 30, 2016

@ansible, ping. This issue is waiting on your response.
click here for bot help

@ansibot
Copy link

ansibot commented Dec 9, 2016

This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible

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.

@stanrate
Copy link
Author

stanrate commented Jan 5, 2017

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:

group_by: key='mygroup1'

was replaced with:

add_host: hostname={{item}} groups='mygroup1'
with_items: "{{ansible_play_hosts}}"

@ansibot
Copy link

ansibot commented Sep 11, 2017

This issue was migrated to ansible/ansible#29452

@ansibot ansibot closed this as completed Sep 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants