Intro
This repo is a smaller part to executing generic ansible commands inside an ansible execution environment using ansible-runner to consume inventory from an external source other than an inventory file.
Here is the repo that is used inside an execution env for those who are curious: https://github.com/cloudguruab/edpm_plugin
If you have questions feel free to open an issue.
Requirements & Dependencies
I have specified all the requirements for this plugin here
- Ansible
pip install ansible
- AWS CLI
pip install boto3
pip install awscli
Setup
Be sure the desired collection is installed if you're pulling from pre-built module
ansible-galaxy collection list # list installed plugins
ansible-galaxy collection install amazon.aws
After running ansible-galaxy collection list
you should see something like this:
Collection Version
----------------- -------
amazon.aws 5.1.0
community.general 5.2.0
openstack.cloud 1.10.0
Once this is done you need to navigate to your aws console and obtain your aws_secret_key
, and aws_public_key
:
#setting up auth
bash-5.1$ aws configure
AWS Access Key ID [None]: key
AWS Secret Access Key [None]: key
Default region name [None]: us-east-1
Default output format [None]: json
Updating your project
We need to update our inventory source with our private_ip
to connect with our instance. Our ansible config file will also map to our inventory source and the plugin we are using.
-
aws_ec2.yml
:
plugin: aws_ec2
regions:
- us-east-1
keyed_groups:
- key: tags.Tagname
filters:
instance-state-name: running
compose:
ansible_host: private_ip
-
ansible.cfg
:
[defaults]
enable_plugins=aws_ec2
inventory=aws_ec2.yml
Testing
Lets look for our host:
ansible-inventory -i aws_ec2.yml --list #look for host
ansible-inventory -i aws_ec2.yml --graph # graph view
Top comments (0)