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

Numerical Group name throws error in yaml formatted hosts file. #77519

Closed
1 task done
arcreigh opened this issue Apr 12, 2022 · 3 comments · Fixed by #77544
Closed
1 task done

Numerical Group name throws error in yaml formatted hosts file. #77519

arcreigh opened this issue Apr 12, 2022 · 3 comments · Fixed by #77544
Assignees
Labels
affects_2.12 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@arcreigh
Copy link

Summary

When attempting to run a simple playbook to get the hostname of a cisco 3750x ansible fails to parse the yaml formatted hosts file. Playbook works with an INI formatted hosts file, however in an effort to use ansible-vault I need to migrate my file to yaml format.

Issue Type

Bug Report

Component Name

apt

Ansible Version

$ ansible --version
ansible [core 2.12.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/arcreigh/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/arcreigh/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True

Configuration

$ ansible-config dump --only-changed
N/A

OS / Environment

Ubuntu 20.04

Steps to Reproduce

#/etc/ansible/hosts
---

all:
  children:
    Network:
      children:
        IOS:
          hosts:
            3750:
              ansible_host: 3750.arc.net
      vars:
        ansible_connection: ansible.netcommon.network_cli
        ansible_network_os: cisco.ios.ios
        ansible_user: redacted
        ansible_password: redacted

#/home/ansible/playbooks/cisco/get_hostname.yml

---

- name: Get Cisco Device Hostname and Version
  connection: ansible.netcommon.network_cli
  gather_facts: false
  hosts: all
  tasks:

    - name: Get config for IOS device
      cisco.ios.ios_facts:
        gather_subset: all
    - name: Display config
      debug:
        msg: "The hostname is {{ ansible_net_hostname }} and the OS version is {{ ansible_net_version }}"

Expected Results

Expected output would be
The hostname is 3750.arc.net and the OS version is (insert ios version here)

Actual Results

ansible-playbook -i /etc/ansible/hosts get_hostname.yml
[WARNING]:  * Failed to parse /etc/ansible/hosts with yaml plugin: argument of type 'int' is not iterable
[WARNING]:  * Failed to parse /etc/ansible/hosts with ini plugin: Invalid host pattern '---' supplied, '---' is normally a sign this is a YAML file.
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Get Cisco Device Hostname and Version] *************************************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP ***********************************************************************************************************************************************************************************

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Apr 12, 2022

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 affects_2.12 bug This issue/PR relates to a bug. module This issue/PR relates to a module. 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 Apr 12, 2022
@arcreigh
Copy link
Author

After a bit of testing changing the group name from "3750" to "switches" allowed me to get the expected output. It appears that numerical group names are not possible at the present time.
This is problematic for network devices that are commonly referred to by their model numbers in larger environments.

@arcreigh arcreigh changed the title Failed to parse /etc/ansible/hosts with yaml plugin: argument of type 'int' is not iterable Numerical Group name throws error in yaml formatted hosts file. Apr 12, 2022
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Apr 14, 2022
@s-hertel s-hertel self-assigned this Apr 14, 2022
@s-hertel
Copy link
Contributor

We don't plan on auto-casting unexpected types to strings in the yaml inventory plugin, but the error should be more helpful about what failed and what type is expected. I've opened a PR to do that: #77544.

@ansibot ansibot added the has_pr This issue has an associated PR. label Apr 14, 2022
@ansible ansible locked and limited conversation to collaborators Apr 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.12 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants