Ansible Dynamic Inventory

Getting started with Ansible Dynamic Inventory for AWS Cloud

Install Python Boto :
##################

# yum install Python-pip

#pip install python-boto

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]: 

Downloading  Ec2.py and  Ec2.ini  file  for Dynamic  Inventory :
#################################################

# 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

Exporting some variables :
#######################

# 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
#####################################################


Comments

  1. worked very well for me..

    ReplyDelete
  2. export ANSIBLE_HOSTS=/etc/ansible/ec2.py

    change this variable to ANSIBLE_INVENTORY to suppress warning

    ReplyDelete
    Replies
    1. sudo apt install ansible python-pip
      pip 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

      Delete
  3. sudo apt install ansible python python-pip || sudo yum install ansible python python-pip
    pip 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

    ReplyDelete

Post a Comment

Popular posts from this blog

DevOps Interview Questions

Calico Certified Operator: AWS Expert Questions & Answers

CKAD Certification Exam Preparation Guide and Tips