ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
14.11k stars 3.43k forks source link

AWX - EC2 dynamic inventory source not grouping properly #11490

Open ivantomica opened 2 years ago

ivantomica commented 2 years ago

Please confirm the following

Summary

Setup I'm working with consists of AWX and a single inventory which has multiple sources consisting of 1 static (sourced from a project) and around 30 dynamic (Amazon EC2) inventory types.

Configuration of each dynamic inventory source is done by using following configuration:

---
# Set Inventory hostname
hostnames:
  - "tag:Name"
  - dns-name
# Add hosts only tagged with Ansible tag
filters:
  tag:Ansible:
    - "True"
    - "true"
  instance-state-name: running
keyed_groups:
  # Add hosts to tag_Name_Value groups for each Name/Value tag pair
  - prefix: tag
    key: tags
  # Group hosts per AWS Owner ID
  - prefix: owner
    key: owner_id | string
compose:
  ansible_host: public_ip_address
  ansible_port: tags.SSHPort|default("22")

Usually, this configuration works as it should from my perspective, as I get the inventory consisting of:

To have the inventory up-to-date, there are scheduled jobs which trigger during the night and around 3-4-5 inventories get sourced at the time with 15 minute pause in between batches.

Issue I'm experiencing with automatic sync is that not all hosts are grouped under the tag_Ansible_True group, but the behavior is hit'n'miss. Sometimes all hosts are under the tag_Ansible_True group, but most of the time there are only about 40-60 hosts there while there should be much more. When manual sync is trigger by going to Inventories > NAME_OF_THE_INVENTORY -> Sources -> Sync all, all hosts show up under the tag_Ansible_True.

While in "broken state", examining any of the hosts in the inventory that's missing from the tag_Ansible_True group I can see that its tags are properly populated

tags:
  Ansible: 'True'
  Environment: staging
  Name: somehostname

This points me into direction that something happens during the host grouping phase while they're being grouped and saved into the inventory. Unfortunately, I'm not so familiar with that part of the system and would appreciate further guidance on how to troubleshoot this further.

Multiple curious things happen:

AWX version

19.5.0

Installation method

kubernetes

Modifications

no

Ansible version

No response

Operating system

No response

Web browser

No response

Steps to reproduce

  1. Dynamic inventory of ~30 soures - Amazon EC2 source - Each source on different AWS account
  2. Configuration set up as in description example
  3. Scheduled sync doesn't import all the hosts all the time.

Expected results

All hosts that have tag Ansible=True are grouped into tag_Ansible_True group

Actual results

Only a subset of hosts that have tag Ansible=True is in tag_Ansible_True Group

Additional information

No response

pratikbin commented 2 years ago

Hey @ivantomica I think I'm relating to this issue.

Configuration of each dynamic inventory source is done by using following configuration:

Can you point me where we can add this configuration, Because I can't

ivantomica commented 2 years ago

Can you point me where we can add this configuration, Because I can't find where to put this configuration?

In AWX you create dynamic inventory source by going to

  1. Inventories
  2. INVENTORYNAME
  3. Sources
  4. Add
  5. Source: Amazon EC2
  6. Source variables field

This source can then be scheduled via schedules tab.

pratikbin commented 2 years ago

So I have to put this 👇 configuration in Source variables field right!

---
# Set Inventory hostname
hostnames:
  - "tag:Name"
  - dns-name
...

image

pratikbin commented 2 years ago

Thanks @ivantomica , I was confused with the title itself Source variables.

I wanted to get all the nodes with specific tag. I used Enabled Variable and Enabled value but it disabled that particular node in inventory and enable rest. It is kind of inverse that i thought. But this (Source variables) helped thanks a lot

image

ivantomica commented 2 years ago

Has anyone experienced similar issues or have similar use-case as we do? Upgrades to the AWX haven't yet resolved the issue, and I am having hard time pinpointing it.

Any guidance on how to troubleshoot this further would be greatly appreciated.

pratikbin commented 2 years ago

I'm not facing this issue in awx 0.21.0