ionos-cloud / module-ansible

Apache License 2.0
10 stars 8 forks source link

Inventory script usage unclear #7

Closed attrib closed 2 years ago

attrib commented 3 years ago

Description

The documentation for the inventory script is unclear to me.

I installed ionos cloud via ansible galaxy. Creating/Updating servers is working fine. But I get confused how I could use the inventory.

If I run ansible-playbook -i ~/.ansible/collections/ansible_collections/ionoscloudsdk/ionoscloud/plugins/inventory/inventory.py test.yml

I get

[WARNING]:  * Failed to parse /home/kfritsche/.ansible/collections/ansible_collections/ionoscloudsdk/ionoscloud/plugins/inventory/inventory.py with script plugin: problem running /home/kfritsche/.ansible/collections/ansible_collections/ionoscloudsdk/ionoscloud/plugins/inventory/inventory.py --list ([Errno 13] Permission denied:
'/home/kfritsche/.ansible/collections/ansible_collections/ionoscloudsdk/ionoscloud/plugins/inventory/inventory.py')

Added +x to the inventory script results in:

[WARNING]:  * Failed to parse /home/kfritsche/.ansible/collections/ansible_collections/ionoscloudsdk/ionoscloud/plugins/inventory/inventory.py with script plugin: Inventory script (/home/kfritsche/.ansible/collections/ansible_collections/ionoscloudsdk/ionoscloud/plugins/inventory/inventory.py) had an execution error: Traceback (most recent call last):
File "/home/kfritsche/.ansible/collections/ansible_collections/ionoscloudsdk/ionoscloud/plugins/inventory/inventory.py", line 100, in <module>     import six ImportError: No module named six

pip install six tells me its already installed.

In theory I should be able to use the inventory as a plugin. So I created a ionos.yml file with this content:

plugin: ionoscloudsdk.ionoscloud.inventory
server_name_as_inventory_hostname: true

And then using ansible-playbook -i inventories/ionos.yml test.yml

This seems to work better as I can even revert the +x on the inventory.py but results in:

usage: ansible-playbook [-h] [--list] [--host HOST] [--datacenters] [--fwrules] [--images] [--lans] [--locations] [--nics] [--servers] [--volumes] [--refresh]
ansible-playbook: error: unrecognized arguments: inventories/ionos.yml hub-test-start.yml

Even it it says ansible-playbook the returend message comes from the inventory script. So ansible is calling it, but the script returns this message and no inventory.

So I'm not sure how to use the inventory.py. Any help would be appreciated.

Expected behavior

Either when calling the inventory.py directly or using the better way as a inventory plugin should work to retrieve the dynamic inventory.

Environment

Ansible version:

ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/kfritsche/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]

Module version:

5.0.2

OS:

Linux 5.4.0-77-generic Ubuntu focal

Configuration Files

test.yml

- hosts:
    - drp
  tasks:
    - debug:
        var: ansible_host
jbuchhammer commented 3 years ago

Does the example of the README in https://github.com/ionos-cloud/module-ansible/tree/master/plugins/inventory work?

attrib commented 3 years ago

I found this back then, but it doesn't describe how to use it with ansible-playbook. In combination with ansible-playbook I get the results describe above and didn't get it running.

jbuchhammer commented 3 years ago

Regarding the plugin approach which returned w/ unrecognizedarguments I thinks it's due to the default behavior of argparse. To be used in this context it, parsing should be done by ArgumentParser.parse_known_args() instead of ArgumentParser.parse_args().

Regarding the six module error I have no clue. Do you have only one Python installation?