0
votes

I am trying to set up a dynamic inventory for Ansible to use with Azure, but I am getting some messages as Ansible is not able to parse my yaml file.

What I did so far:

  1. Created Azure Service Principal and added credentials to /home/user/.azure/credentials (I know they recommend placing them in /home/.azure/credentials and I tried that, but it seems that my Ansible looks for them in the /home/user directory.

  2. I placed both the python plugin (the original, unedited plugin) and its yaml config file in /etc/ansible/inventory_plugins. The config file looks like this:

plugin: azure_rm

include_vm_resource_groups:

- vm_1197_rg

auth_source: auto
  1. Testing the functionality with: ansible all -m ping -i ./myazure_rm.yml

The output:

ansible 2.8.1 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.5 (default, Apr 9 2019, 14:30:50) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] Using /etc/ansible/ansible.cfg as config file Skipping due to inventory source not existing or not being readable by the current user azure_rm declined parsing /etc/ansible/inventory_plugins/myazure_rm.yml as it did not pass it's verify_file() method [WARNING]: Unable to parse /etc/ansible/inventory_plugins/myazure_rm.yml 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'

2

2 Answers

0
votes

'When using the azure_rm inventory plugin, the NAME of the inventory file actually matters for parsing.

It has to end with either of the following:

  • azure_rm.yml
  • azure_rm.yaml

E.g any of the following filenames are valid:

  • inventory_azure_rm.yml
  • inventoryazure_rm.yml
  • why_is_this_a_good_idea_azure_rm.yml

If the file does not end with azure_rm.yml you will get a generic error message like so:

[WARNING]:  * Failed to parse $FILENAME with auto plugin: inventory config '$FILENAME ' could not be verified by plugin 'azure_rm'
-1
votes

It seems that I was using the wrong extension when running the command. I was using .yml instead of using .yaml like the file is actually called.