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

Failed to parse hcloud.yml with ansible_collections.hetzner.hcloud.plugins.inventory.hcloud plugin: 'NoneType' object has no attribute 'ip' #258

Closed
mzhaase opened this issue Jul 11, 2023 · 2 comments
Labels
usage This is an usage issue

Comments

@mzhaase
Copy link

mzhaase commented Jul 11, 2023

SUMMARY
> HCLOUD_TOKEN=$HCLOUD_TOKEN ansible-inventory --list
[WARNING]:  * Failed to parse .../hcloud.yml with ansible_collections.hetzner.hcloud.plugins.inventory.hcloud plugin: 'NoneType' object has no attribute 'ip'
[WARNING]: Unable to parse /home/haase/work/bytecookie/bytecookie-ansible/hcloud.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible_collections.hetzner.hcloud.plugins.inventory.hcloud

ANSIBLE VERSION
5.10.0-1ppa~focal
COLLECTION VERSION
1.15.0
CONFIGURATION
COLLECTIONS_PATHS(.../ansible.cfg) = ['.../galaxy/collections']
DEFAULT_HOST_LIST(.../ansible.cfg) = ['.../hcloud.yml']
DEFAULT_ROLES_PATH(.../ansible.cfg) = ['.../galaxy/roles', '.../roles']
INVENTORY_ENABLED(.../ansible.cfg) = ['hcloud']
OS / ENVIRONMENT

Ubuntu 20.04.6 LTS

STEPS TO REPRODUCE
ansible-galaxe install hetzner.hcloud
pip3 install hcloud

#ansible.cfg
[defaults]
inventory = hcloud.yml
roles_path = ./galaxy/roles:./roles
collections_path = ./galaxy/collections

[inventory]
enable_plugins = hcloud

#hcloud.yml
plugin: hcloud

ansible-inventory --list
EXPECTED RESULTS

List the hosts.

ACTUAL RESULTS

HCLOUD_TOKEN=$HCLOUD_TOKEN ansible-inventory --list -vvv
ansible-inventory [core 2.12.10]
config file = .../ansible.cfg
configured module search path = ['/.../.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = .../galaxy/collections
executable location = /usr/bin/ansible-inventory
python version = 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0]
jinja version = 2.10.1
libyaml = True
Using .../ansible.cfg as config file
redirecting (type: inventory) ansible.builtin.hcloud to hetzner.hcloud.hcloud
[WARNING]: * Failed to parse .../hcloud.yml with ansible_collections.hetzner.hcloud.plugins.inventory.hcloud plugin: 'NoneType' object has no attribute 'ip'
File "/usr/lib/python3/dist-packages/ansible/inventory/manager.py", line 290, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python3/dist-packages/ansible_collections/hetzner/hcloud/plugins/inventory/hcloud.py", line 262, in parse
self._set_server_attributes(server)
File "/usr/lib/python3/dist-packages/ansible_collections/hetzner/hcloud/plugins/inventory/hcloud.py", line 188, in _set_server_attributes
self.inventory.set_variable(server.name, "ipv4", to_native(server.public_net.ipv4.ip))
[WARNING]: Unable to parse .../hcloud.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available

@jooola
Copy link
Collaborator

jooola commented Jul 13, 2023

Hi @mzhaase,
I reproduced your error by using the older version of the hetzner.hcloud collection bundled within the ansible package.

Please make sure that you installed the newer version of the hetzner.hcloud collection from ansible-galaxy, the command you wrote in the reproduction steps was invalid:

ansible-galaxe install hetzner.hcloud

You can use the following instead:

ansible-galaxy collection install hetzner.hcloud

To reproduce:

# We have a server without ipv4
hcloud server create --name tmp --type cx11 --image debian-12 --without-ipv4

docker run -it --rm -v $(pwd):/src ubuntu:20.04 bash

cd /src
apt update
apt install software-properties-common
add-apt-repository ppa:ansible/ansible
apt install ansible python3-pip
pip3 install hcloud

ansible --version

export HCLOUD_TOKEN=$HCLOUD_TOKEN

## This is not working
ansible-inventory --list -vvv

## This is working
ansible-galaxy collection install hetzner.hcloud
ansible-inventory --list -vvv

@jooola jooola added the usage This is an usage issue label Jul 13, 2023
@mzhaase
Copy link
Author

mzhaase commented Jul 20, 2023

Hi,
indeed, it happens when using plugin: hcloud instead of plugin: hetzner.hcloud.hcloud

@mzhaase mzhaase closed this as completed Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usage This is an usage issue
Projects
None yet
Development

No branches or pull requests

2 participants