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

Empty hosts declaration in YAML inventory causes partial fallback to INI parsing #34760

Closed
wfaulk opened this issue Jan 11, 2018 · 11 comments
Closed
Assignees
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. collection Related to Ansible Collections work inventory Inventory category support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@wfaulk
Copy link

wfaulk commented Jan 11, 2018

ISSUE TYPE
  • Bug Report
COMPONENT NAME

inventory

ANSIBLE VERSION
ansible 2.4.2.0
  config file = None
  configured module search path = [u'/Users/wfaulk/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.4.2.0_2/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.10 (default, Feb  7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
CONFIGURATION

default environment, no config or envvars

OS / ENVIRONMENT

running from MacOS 10.12.6
managing N/A

SUMMARY

YAML inventories where a group contains a "hosts:" group, but no hosts exist inside the group cause ansible to interpret the file partially as just a list of hosts, without warning.

STEPS TO REPRODUCE

Running ansible all --list-hosts against the following inventory file lists 10 hosts, when it should only list 3.

all:
  hosts:
    host1:
  children:
    group1:
      hosts:
      children:
        group1a:
          hosts:
            host2:
    group2:
      hosts:
        host3:

Note that "group1" contains a "hosts" entry, but there are no hosts listed. If you delete that line, the inventory file works correctly.

EXPECTED RESULTS
  hosts (3):
    host2
    host3
    host1
ACTUAL RESULTS
ansible 2.4.2.0
  config file = None
  configured module search path = [u'/Users/wfaulk/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.4.2.0_2/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.10 (default, Feb  7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
No config file found; using defaults
Parsed <redacted>/bug1.yml inventory source with ini plugin
  hosts (10):
    all:
    hosts:
    host1:
    children:
    group1:
    group1a:
    host2:
    group2:
    host3:
    host1

Note that, somehow, both "host1" and "host1:" are included, which seems to indicate that it's somehow parsing it as YAML and as INI.

@ansibot
Copy link
Contributor

ansibot commented Jan 11, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report inventory Inventory category needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jan 11, 2018
@mkrizek
Copy link
Contributor

mkrizek commented Jan 12, 2018

cc @bcoca

@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Jan 12, 2018
@SethosII
Copy link

SethosII commented Feb 8, 2018

This also affects 2.5.

$ cat hosts.yaml 
a:
  hosts:
    ubuntu-server:
b:
  hosts:
  children:
    a:
$ git clone https://github.com/ansible/ansible.git
$ cd ansible/
$ source ./hacking/env-setup
$ ansible --version
ansible 2.5.0 (devel 663c410da4) last updated 2018/02/08 07:28:30 (GMT +200)
  config file = /home/itadmin/.ansible.cfg
  configured module search path = [u'/home/itadmin/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /dev/shm/ansible/lib/ansible
  executable location = /dev/shm/ansible/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
$ ansible -i ../hosts.yaml -u user -m ping all
b: | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname b:: Temporary failure in name resolution\r\n", 
    "unreachable": true
}
ubuntu-server: | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname ubuntu-server:: Temporary failure in name resolution\r\n", 
    "unreachable": true
}
children: | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname children:: Temporary failure in name resolution\r\n", 
    "unreachable": true
}
a: | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname a:: Temporary failure in name resolution\r\n", 
    "unreachable": true
}
hosts: | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname hosts:: Temporary failure in name resolution\r\n", 
    "unreachable": true
}
ubuntu-server | SUCCESS => {
    "changed": false, 
    "failed": false, 
    "ping": "pong"
}

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@pandatk
Copy link

pandatk commented Oct 4, 2018

Can confirm the issue is still there in 2.6.4

@bcoca bcoca self-assigned this Oct 4, 2018
@corbinstuard
Copy link

Can confirm the issue still exists in 2.7.5

@ansibot
Copy link
Contributor

ansibot commented Mar 28, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Mar 28, 2020
@ansibot ansibot added collection Related to Ansible Collections work collection:openstack.cloud needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 29, 2020
@ansibot ansibot removed collection:openstack.cloud needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Jul 14, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 24, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

@ansibot ansibot closed this as completed Aug 24, 2020
@mkrizek mkrizek reopened this Aug 24, 2020
@mkrizek
Copy link
Contributor

mkrizek commented Aug 24, 2020

!component =lib/ansible/plugins/inventory/yaml.py

@mkrizek
Copy link
Contributor

mkrizek commented Aug 24, 2020

!needs_collection_redirect

@ansibot
Copy link
Contributor

ansibot commented Aug 24, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Aug 24, 2020
@bcoca
Copy link
Member

bcoca commented Jan 20, 2021

fixed via #45499 and #48883
included in 2.8 and newer versions.

@bcoca bcoca closed this as completed Jan 20, 2021
@ansible ansible locked and limited conversation to collaborators Feb 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. collection Related to Ansible Collections work inventory Inventory category 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