JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Gallery
DevOps
Kubernetes (K8s)
Docker
HELM
Ansible
Linux Commands
More
Share
Explore
Ansible
Dynamic Inventory file
To get list of inventory plugins
ansible-doc -t inventory -l
Steps to dynamically get hosts from aws
Add Enable plugin syntax in ansible cfg file
(Ansible Manager Machine)
[inventory]
enable_plugin = host_list,script,auto,yaml,ini,toml
2.
Install boto3(aws uses boto packages to connect with cloud)
(Ansible Manager Machine)
pip3 install boto3
pip3 install botocore
3. Create AWS User and export creds on ansible engine
(Ansible Manager Machine)
Using env variable add the AWS_ACCESS_KEY AND AWS_SECRET_KEY in ansible engine
export AWS_ACCESS_KEY=''
export AWS_SECRET_KEY=''
4. Create yml file for AWS plugin
(
AWS_PLUGIN_FILE_NAME.yml)
plugin: amazon.aws.aws_ec2
filters:
instance-state-name: running
5. Now we can verify and populate our dynamic inventory using the command:
ansible-inventory -i <AWS_PLUGIN_FILE_NAME> --graph
To get full information use --list
ansible-inventory -i <AWS_PLUGIN_FILE_NAME> --list
6. Using dynamic inventory file to ping the machines using a adhoc command
ansible all -i <AWS_PLUGIN_FILE_NAME> -m ping
To pass a specific user through which we want to connect to our aws machine we can use
-u flag
ansible all -i <AWS_PLUGIN_FILE_NAME>
-u ec2_user
-m ping
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.