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.
More on AWX, AAP and Cloud Integration
AWX or Red Hat Ansible Automation Platform: what is the difference and what do you pay for?BeginnerWhat are the core objects in AWX and how do they fit together?BeginnerHow do you manage AWX configuration as code?IntermediateHow do custom credential types work in AWX?AdvancedHow do you connect AWX to an external secrets manager?IntermediateHow do you trigger AWX jobs from CI or other systems?Intermediate