Ansible Dynamic inventory
- Ansible supports dynamic inventory.
- Dynamic inventory can be acheived by
- Refer Here for official docs
- Dynamic inventory in script form can be written in any language of your choice. The condition is this file has to be executable.
- Ansible dynamic inventory should return data in the below format
{
"_meta": {
"hostvars": {
"instance-01": {
"aws_ami_launch_index_ec2": 0,
"aws_architecture_ec2": "x86_64",
"ebs_optimized": false,
"ec2_tag_Environment": "dev",
"ec2_tag_Name": "instance-01",
"ec2_tag_Tag1": "Test1",
"ec2_tag_Tag2": "Test2",
"ena_support": true,
"enclave_options": {
"enabled": false
}
},
"instance-02": {
"ebs_optimized": false,
"ec2_tag_Environment": "dev",
"ec2_tag_Name": "instance-02",
"ec2_tag_Tag1": "Test3",
"ec2_tag_Tag2": "Test4",
"ena_support": true,
"enclave_options": {
"enabled": false
}
}
}
},
"all": {
"children": [
"aws_ec2",
"ungrouped"
]
},
"aws_ec2": {
"hosts": [
"instance-01",
"instance-02"
]
}
}
Ansible in CI/CD Pipelines
- Two ways of using ansible in CI/CD
- Directly from CI/CD

- From Infra Provisioning

Ansible Vault