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

Facing issue with contrib/inventory_builder/inventory.py #8507

Closed
ajaibsingh opened this issue Feb 5, 2022 · 2 comments · Fixed by #8554
Closed

Facing issue with contrib/inventory_builder/inventory.py #8507

ajaibsingh opened this issue Feb 5, 2022 · 2 comments · Fixed by #8554

Comments

@ajaibsingh
Copy link

Hello Team,

1st of all! My expectation from the inventory.py while using the "print_hostnames" option is as follows:

It will scan the inventory file specified by the CONFIG_FILE=inventory/mycluster/hosts.yaml variable and print out the name of hosts to stdout.

If that is not the way how the print_hostnames option works, then please provide the documents.

If my expectation is correct, then I am facing the following error:

Traceback (most recent call last):
  File "contrib/inventory_builder/inventory.py", line 472, in <module>
    sys.exit(main())
  File "contrib/inventory_builder/inventory.py", line 467, in main
    KubesprayInventory(argv, CONFIG_FILE)
  File "contrib/inventory_builder/inventory.py", line 92, in __init__
    self.parse_command(changed_hosts[0], changed_hosts[1:])
  File "contrib/inventory_builder/inventory.py", line 413, in parse_command
    self.print_ips()
  File "contrib/inventory_builder/inventory.py", line 459, in print_ips
    for host, opts in self.yaml_config['all']['hosts'].items():
KeyError: 'all'

Can anyone help me?
I am using Kubespray 2.17.

@oomichi
Copy link
Contributor

oomichi commented Feb 17, 2022

@ajaibsingh Thank you for reporting this issue.
I confirmed this issue can be reproduced on my side:

$ declare -a IPS=(192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5)
$ CONFIG_FILE=./test-hosts.yaml python3 ./inventory.py $ cat test-hosts.yaml 
all:
  hosts:
    node1:
      ansible_host: 192.168.1.1
      ip: 192.168.1.1
      access_ip: 192.168.1.1
    node2:
      ansible_host: 192.168.1.2
      ip: 192.168.1.2
      access_ip: 192.168.1.2
    node3:
      ansible_host: 192.168.1.3
      ip: 192.168.1.3
      access_ip: 192.168.1.3
    node4:
      ansible_host: 192.168.1.4
      ip: 192.168.1.4
      access_ip: 192.168.1.4
    node5:
      ansible_host: 192.168.1.5
      ip: 192.168.1.5
      access_ip: 192.168.1.5
  children:
    kube_control_plane:
      hosts:
        node1:
        node2:
    kube_node:
      hosts:
        node1:
        node2:
        node3:
        node4:
        node5:
    etcd:
      hosts:
        node1:
        node2:
        node3:
    k8s_cluster:
      children:
        kube_control_plane:
        kube_node:
    calico_rr:
      hosts: {}
$ CONFIG_FILE=./test-hosts.yaml python3 ./inventory.py print_hostnames
Traceback (most recent call last):
  File "./inventory.py", line 472, in <module>
    sys.exit(main())
  File "./inventory.py", line 467, in main
    KubesprayInventory(argv, CONFIG_FILE)
  File "./inventory.py", line 92, in __init__
    self.parse_command(changed_hosts[0], changed_hosts[1:])
  File "./inventory.py", line 415, in parse_command
    self.print_hostnames()
  File "./inventory.py", line 455, in print_hostnames
    print(' '.join(self.yaml_config['all']['hosts'].keys()))
KeyError: 'all'

@oomichi
Copy link
Contributor

oomichi commented Feb 17, 2022

found the root cause and submitted a pull request for fixing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants