Azure Dynamic Inventory not fetching resource group failed with status code 404

Viewed 24

Just started working on ansible dynamic inventory for azure, followed steps given by Azure documentation.

Created Service Principle with scope over below 2 resource group(redacted the names) When I am trying with the first resource group(service principle has scope over its subscription) I get the output of the virtual machines but not for the other(even when I add this second I get below output as error

plugin: azure.azcollection.azure_rm
include_vm_resource_groups:
  - <redacted>
  - <redacted>


auth_source: credential_file

keyed_groups:
  - prefix: tag
    key: tags
  - prefix: loc
    key: location

Error:

/home/user/.local/share/virtualenvs/project-UFwkwC88/lib/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  from cryptography.exceptions import InvalidSignature
Using /etc/ansible/ansible.cfg as config file
[WARNING]:  * Failed to parse /home/user/project/ansible/inventories/azure/azure_rm.yaml with auto plugin: a batched request
failed with status code 404, url /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Compute/virtualMachines
[WARNING]:  * Failed to parse /home/user/project/ansible/inventories/azure/azure_rm.yaml with yaml plugin: Plugin
configuration YAML file, not YAML inventory
[WARNING]:  * Failed to parse /home/user/project/ansible/inventories/azure/azure_rm.yaml with ini plugin: Invalid host
pattern 'plugin:' supplied, ending in ':' is not allowed, this character is reserved to provide a port.
[WARNING]: Unable to parse /home/user/project/ansible/inventories/azure/azure_rm.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
@all:
  |--@ungrouped:
1 Answers

The issue was, I was trying to access virtual machines from different subscription ids.

To resolve this access issue I created profile in ~/.azure/credentials file

[profile_1]
subscription_id= xxx
tenant = xxx
client_id = xxx
secret = xxx

[profile_2]
subscription_id= xxx
tenant = xxx
client_id = xxx
secret = xxx

And created separate azure_rm.yaml files for these different subscription id like below

plugin: azure.azcollection.azure_rm
include_vm_resource_groups:
  - <rg in subscription 2>
auth_source: credential_file
profile: profile_2
Related