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

Cobbler inventory script should ignore hosts with `dns_name is None`, not just `dns_name == ''` #24546

Closed
movermeyer opened this Issue May 12, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@movermeyer
Contributor

movermeyer commented May 12, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
CONFIGURATION

No changes to ansible.cfg

OS / ENVIRONMENT

N/A

SUMMARY

The Cobbler inventory script discards hosts that have the empty string for a DNS name, but not those that fail to set the dns_name variable at all (ie. leave it as None).

STEPS TO REPRODUCE

Create a system in cobbler with a single static interface and no DNS name.

sudo cobbler system add --name=test --profile=centos7-x86_64 --interface=eth0 --static=1

Then run cobbler.py

python cobbler.py
EXPECTED RESULTS

The host with no DNS name would also be ignored, as claimed at the top of cobbler.py.

ACTUAL RESULTS

When called implicitly as part of any ansible command, cobbler.py returns a JSON object with a null hostname

  "production": [
    "10.235.37.103", 
    null, 
    "10.235.36.109"
  ]

Which causes Ansible to fail when it tries to load the inventory:

Traceback (most recent call last):
  File "env/bin/ansible-playbook", line 109, in <module>
    exit_code = cli.run()
  File "env/lib/python2.7/site-packages/ansible/cli/playbook.py", line 128, in run
    inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
  File "env/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 98, in __init__
    self.parse_inventory(host_list)
  File "env/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 175, in parse_inventory
    for host in self.get_hosts(ignore_limits=True, ignore_restrictions=True):
  File "env/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 247, in get_hosts
    hosts = self._evaluate_patterns(patterns)
  File "env/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 345, in _evaluate_patterns
    that = self._match_one_pattern(p)
  File "env/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 398, in _match_one_pattern
    hosts = self._enumerate_matches(expr)
  File "env/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 489, in _enumerate_matches
    matching_hosts = self._match_list(group.get_hosts(), 'name', pattern)
  File "env/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 220, in _match_list
    if pattern.match(getattr(item, item_attr)):
TypeError: expected string or buffer

There's a check for dns_name == '', but there should also be a check for dns_name is None

@movermeyer movermeyer changed the title from Cobbler inventory script should ignore hosts with dns_name == None, not just == '' to Cobbler inventory script should ignore hosts with dns_name is None, not just == '' May 12, 2017

@movermeyer movermeyer changed the title from Cobbler inventory script should ignore hosts with dns_name is None, not just == '' to Cobbler inventory script should ignore hosts with `dns_name is None`, not just `dns_name == ''` May 12, 2017

movermeyer added a commit to movermeyer/ansible that referenced this issue May 12, 2017

@movermeyer

This comment has been minimized.

Contributor

movermeyer commented May 12, 2017

P.S: Can I ask why it is ignoring static interfaces anyway?

It seems to me that static interfaces could be assigned DNS names.

ansibot added a commit that referenced this issue Aug 18, 2017

prasadkatti pushed a commit to prasadkatti/ansible that referenced this issue Oct 1, 2017

@ansibot ansibot added bug and removed bug_report labels Mar 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment