Interview Prep/Ansible/AWX, AAP and Cloud Integration

How do you use Ansible to audit cloud resources for compliance?

IntermediateProductionAWX, AAP and Cloud Integration
Answer

Use the _info modules, which only read, and assert on the results. A nightly read-only job is low risk and catches drift that never passed through your IaC.

- hosts: localhost
  gather_facts: false
  tasks:
    - amazon.aws.ec2_instance_info:
        region: ap-south-1
        filters:
          instance-state-name: running
      register: ec2

    - name: Find instances missing required tags
      ansible.builtin.set_fact:
        untagged: "{{ ec2.instances | rejectattr('tags.owner', 'defined') | map(attribute='instance_id') | list }}"

    - ansible.builtin.fail:
        msg: "Instances without an owner tag: {{ untagged }}"
      when: untagged | length > 0

Run it with a read-only IAM role and send the failure notification to the owning team. For broad cloud compliance, AWS Config or a CSPM tool is the better primary control; Ansible audits fill specific gaps.

All Ansible questions Roadmap: Ansible

More on AWX, AAP and Cloud Integration