Ansible Dynamic Inventory
Getting started with Ansible Dynamic Inventory for AWS Cloud
# pip install awscli
AWS CLI CONFIGURATION :
########################
# aws configure
AWS Access Key ID [****************W5UQ]:
AWS Secret Access Key [****************0QTW]:
Default region name [us-west-2]:
Default output format [None]:
Downloading Ec2.py and Ec2.ini file for Dynamic Inventory :
#################################################
# cd /etc/ansible/
Install Python Boto :
##################
# yum install Python-pip
#pip install python-boto
AWS CLI Installation :
###################
AWS CLI Installation :
###################
# pip install awscli
AWS CLI CONFIGURATION :
########################
# aws configure
AWS Access Key ID [****************W5UQ]:
AWS Secret Access Key [****************0QTW]:
Default region name [us-west-2]:
Default output format [None]:
#################################################
# cd /etc/ansible/
# wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py
# wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
# chmod +x ec2.py ec2.ini
# wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
# chmod +x ec2.py ec2.ini
Exporting some variables :
#######################
# export ANSIBLE_HOSTS=/etc/ansible/ec2.py
# export ANSIBLE_INI=/etc/ansible/ec2.ini
#######################
# export ANSIBLE_HOSTS=/etc/ansible/ec2.py
# export ANSIBLE_INI=/etc/ansible/ec2.ini
Now get all running Instances details info :
###################################
###################################
# /etc/ansible/ec2.py --list
Checking Ping module if firewall is configured :
#####################################
#####################################
# ansible all -u ec2-user --private-key /home/shashank/Downloads/key1.pem -m ping
52.41.118.0 | SUCCESS => {
"changed": false, "ping": "pong"}
All done ! Now deploy your applications on AWS Cloud using Ansible
#####################################################
#####################################################
worked very well for me..
ReplyDeleteexport ANSIBLE_HOSTS=/etc/ansible/ec2.py
ReplyDeletechange this variable to ANSIBLE_INVENTORY to suppress warning
sudo apt install ansible python-pip
Deletepip install boto
cd /etc/ansible
sudo wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
sudo wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py
sudo chmod +x ec2.py
sudo sed -i s~"$(cat /etc/ansible/ec2.ini | grep "vpc_destination_variable = ip_address")"~"vpc_destination_variable = private_ip_address"~g /etc/ansible/ec2.ini
sudo sed -i s~"$(cat /etc/ssh/ssh.config | grep "StrictHostKeyChecking")"~"StrictHostKeyChecking no"~g /etc/ssh/ssh.config
echo "export ANSIBLE_INVENTORY=/etc/ansible/ec2.py" >> ~/.bashrc
echo "export ANSIBLE_INI=/etc/ansible/ec2.ini" >> ~/.bashrc
echo "export EC2_INSTANCE_FILTERS='tag:Name=rancher-*'" >> ~/.bashrc
sudo apt install ansible python python-pip || sudo yum install ansible python python-pip
ReplyDeletepip install boto
cd /etc/ansible
sudo wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
sudo wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py
sudo chmod +x ec2.py
sudo sed -i s~"vpc_destination_variable = ip_address"~"vpc_destination_variable = private_ip_address"~g /etc/ansible/ec2.ini
sudo sed -i s~"$(cat /etc/ansible/ec2.ini | grep "regions = ")"~"regions = us-east-1"~g /etc/ansible/ec2.ini
sudo sed -i s~"StrictHostKeyChecking ask"~"StrictHostKeyChecking no"~g /etc/ssh/ssh_config
echo "export ANSIBLE_INVENTORY=/etc/ansible/ec2.py" >> ~/.bashrc
echo "export ANSIBLE_INI=/etc/ansible/ec2.ini" >> ~/.bashrc
echo "export EC2_INSTANCE_FILTERS='tag:Name=rancher-*'" >> ~/.bashrc
source ~/.bashrc