azure icon indicating copy to clipboard operation
azure copied to clipboard

azure_rm: ignore 404 error for a resource group

Open sugitk opened this issue 3 years ago • 2 comments

SUMMARY

A resource group may return 404 error for some reasons and then the inventory sync fails.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

azure_rm

ADDITIONAL INFORMATION

When specifying a resource group that is not defined in the subscription, the inventory sync failed with the reason only because this resource group returned 404 error.

plugin: a batched request failed with status code 404, url
/subscriptions/xxxxxxxxxxxxxxxxxxxxx/resourceGroups/foobar/providers/Microsoft.Compute/virtualMachines
  File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py", line 280, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/auto.py", line 58, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/var/lib/awx/vendor/awx_ansible_collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 206, in parse
    self._get_hosts()
  File "/var/lib/awx/vendor/awx_ansible_collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 263, in _get_hosts
    self._process_queue_batch()
  File "/var/lib/awx/vendor/awx_ansible_collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 405, in _process_queue_batch
    raise AnsibleError("a batched request failed with status code {0}, url {1}".format(status_code, result.url))
[WARNING]: Unable to parse
/data/awx/tmp/bwrap_3159_u4ncawor/awx_3159_xs230zov/azure_rm.yml as an
inventory source
ERROR! No inventory was parsed, please check your configuration and options.

The customer states that this 404 causes during peak hours only. So we need an additional parameter to skip this error not to fail the whole job like fail_on_template_errors.

sugitk avatar Aug 16 '21 00:08 sugitk

@sugitk Thank you for submitting this question? Can you help provide the process for finding this problem? Thank you very much!

Fred-sun avatar Aug 16 '21 06:08 Fred-sun

@Fred-sun Thank you too, I am a Senior TSE for Ansible Automation Platform of Red Hat and I received a query from a customer regarding this issue today.

I tested to create some resource groups in a subscription and I specified the groups in the parameter for this inventory plugin as follows.

conditional_groups:
  azure: true
default_host_filters: []
fail_on_template_errors: false
hostvar_expressions:
  computer_name: name
  private_ip: private_ipv4_addresses[0] if private_ipv4_addresses else None
  provisioning_state: provisioning_state | title
  public_ip: public_ipv4_addresses[0] if public_ipv4_addresses else None
  public_ip_id: public_ip_id if public_ip_id is defined else None
  public_ip_name: public_ip_name if public_ip_name is defined else None
  tags: tags if tags else None
  type: resource_type
keyed_groups:
- key: location
  prefix: ''
  separator: ''
- key: tags.keys() | list if tags else []
  prefix: ''
  separator: ''
- key: security_group
  prefix: ''
  separator: ''
- key: resource_group
  prefix: ''
  separator: ''
- key: os_disk.operating_system_type
  prefix: ''
  separator: ''
- key: dict(tags.keys() | map("regex_replace", "^(.*)$", "\1_") | list | zip(tags.values() | list)) if tags else []
  prefix: ''
  separator: ''
plain_host_names: true
plugin: azure.azcollection.azure_rm
use_contrib_script_compatible_sanitization: true
include_vm_resource_groups:
- 'myrg1'
- 'foobar'

The above 'myrg1' resource group exists but 'foobar' doesn't.

If you need more information to reproduce the issue, please let me know :)

sugitk avatar Aug 16 '21 07:08 sugitk