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

[ansible 2.0] from dynamic inventory, groups showing as hosts #13655

Closed
senorsmile opened this issue Dec 24, 2015 · 5 comments
Closed

[ansible 2.0] from dynamic inventory, groups showing as hosts #13655

senorsmile opened this issue Dec 24, 2015 · 5 comments
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. 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.
Milestone

Comments

@senorsmile
Copy link

senorsmile commented Dec 24, 2015

ISSUE TYPE
  • Bug Report
COMPONENT NAME
  • dynamic inventory
ANSIBLE VERSION
  • v2.0.0-0.8.rc3
  • v2.0.0.0-1
  • v2.0.0.1-1
  • v2.0.0.2-1

We are noticing some errors while testing on ansible v2.0 (now rc3), where "sub-groups" are being mentioned as failing nodes.

I have narrowed this down to a reproducible case. Note that it does NOT happen with "subgroups" in a plain hosts file. Only when coming from a dynamic inventory script.

Say you have the following output from your dynamic inventory:

{
'group1': {
  'children': [
    'group1_1',
    'group1_2'
  ]
},
'group1_1': [
  'host1',
  'host2'
]
}

now, try to run e.g.

ansible group1 --list-hosts

Under ansible 1.9.4 you will only get the hosts.
In 2.0 you get the hosts PLUS group1_1.

I have narrowed this down a bit.

It did NOT happen at this commit:

commit e36b7130ff1c5366ab1c767641a8819d4fdf5e5f
Merge: 9a90ca5 d2ba0de
Author: Brian Coca <bcoca@ansible.com>
Date:   Mon Jun 1 11:01:59 2015 -0400

A couple of unworking merges later, it starts happening:

commit 860a96cf7068e907c8e645e2325e5e4e58bb20f3
Merge: bc041ff caf3cf6
Author: Brian Coca <bcoca@ansible.com>
Date:   Tue Jun 2 10:25:45 2015 -0400

I have not yet been able to track down the issue in code. This has been reproduced on multiple machines and Mac OS and Ubuntu 14.04.

@jimi-c jimi-c added this to the v2 milestone Dec 31, 2015
nflx pushed a commit to nflx/ansible that referenced this issue Jan 8, 2016
and without hosts and vars

Without this patch, the simplified syntax is triggered when a group
is defined like this:

    "platforms": {
        "children": [
            "cloudstack"
        ]
    }

Which results in a group 'platforms' with 1 host 'platforms'.

more details in ansible#13655
@nflx
Copy link

nflx commented Jan 8, 2016

This commit removed 'children' from this line
ce3ef7f#diff-a4d695beaa410b22bfeb22749cdaa210R99
When I add that again it works for me.

Also this issue has been resolved before?
69740b8

A possible workaround to the dynamic inventory script could be to add a 'vars' key with empty dict as value {} but I don't know any other implications of this... so yeah.

{
'group1': {
  'children': [
    'group1_1',
    'group1_2'
  ]
  ,
  'vars' : {}
},
'group1_1': [
  'host1',
  'host2'
]
}

nflx pushed a commit to nflx/ansible-inventory that referenced this issue Jan 8, 2016
ansible/ansible#13655

... where groups gets added as hosts to the inventory.
That does not happen if group has vars defined, so we
give all groups at least an empty dict of vars.
@senorsmile
Copy link
Author

@nflx Your fix in the ansible-inventory module you're using is perfect. The dynamic inventory that I'm using is internal and highly customized for our environment, but this workaround should be easy to implement. Plus, that implementation gives me great ideas to add to our dynamic inventory. Thanks!

bcoca pushed a commit that referenced this issue Jan 12, 2016
and without hosts and vars

Without this patch, the simplified syntax is triggered when a group
is defined like this:

    "platforms": {
        "children": [
            "cloudstack"
        ]
    }

Which results in a group 'platforms' with 1 host 'platforms'.

more details in #13655
@camerondavison
Copy link

did this bug get missed. it looks like it was marked for the stable milestone, and 2.0 is released https://www.ansible.com/blog/ansible-2.0-launch and this still exists. I have a pretty simple script generating something like.

{
  "ephemeral-172_31_41_195": {
    "hosts": [
      "172.31.41.195"
    ]
  },
  "ephemeral": {
    "children": [
      "ephemeral-172_31_41_195",
      "ephemeral-172_31_35_68"
    ]
  },
  "ephemeral-172_31_35_68": {
    "hosts": [
      "172.31.35.68"
    ]
  }
}

which broke, but when I added the "vars": {} line fixed it

{
  "ephemeral-172_31_41_195": {
    "hosts": [
      "172.31.41.195"
    ]
  },
  "ephemeral": {
    "vars": {},
    "children": [
      "ephemeral-172_31_41_195",
      "ephemeral-172_31_35_68"
    ]
  },
  "ephemeral-172_31_35_68": {
    "hosts": [
      "172.31.35.68"
    ]
  }
}

Im pretty glad I came across this issue because I had no idea why things all of a sudden just broke so badly. all of the configs that were attached to the host "ephemeral" all of a sudden did not work, since it was actually trying to resolve that as a host name.

@bcoca bcoca modified the milestones: stable-2.0, stable-2.1 Sep 6, 2016
@ansibot ansibot added triage affects_2.2 This issue/PR affects Ansible v2.2 labels Sep 7, 2016
@ansibot ansibot added the affects_2.3 This issue/PR affects Ansible v2.3 label Dec 13, 2016
@bcoca bcoca removed the triage label Dec 16, 2016
@ansibot
Copy link
Contributor

ansibot commented Apr 11, 2017

@senorsmile 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:

  • issue type
  • ansible version
  • component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

@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. labels Apr 11, 2017
@senorsmile
Copy link
Author

I updated the original request and retested from git several different versions of 2.0.x.

It appears that as of 2.0.1 this bug is no longer present.

I have tested it is NOT present on:

  • v2.0.1.0-1
  • v2.0.2.0-1
  • v2.1.5.0-1
  • v2.2.2.0-1
  • v2.3.0.0-0.6.rc6

Since it seems to have been incidentally fixed in 2.0.1, marking this as closed.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. 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.
Projects
None yet
Development

No branches or pull requests

6 participants