Aws Cloud is so vast in services and it will be great if we can integrate with Ansible :
Requirment :
Requirment :
- setup and install ansible
- install boto 2.24.0 +
Note : I am using ubuntu 16.04 for setting up amazon dynamic Inventory.
Steps :
- Installing ansible and boto
root@adhoc:~# sudo apt-add-repository ppa:ansible/ansible
root@adhoc:~# sudo apt update
root@adhoc:~# sudo apt install ansible
BOTO Installation :
root@adhoc:~# sudo apt install python-pip
root@adhoc:~# pip install boto
AWS CLI Installation :
root@adhoc:~# pip install awscli
AWS CLI CONFIGURATION :
adhoc@adhoc:~$ sudo -i
[sudo] password for adhoc:
root@adhoc:~# 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
root@adhoc:~# cd /etc/ansible/
root@adhoc:~# wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py
root@adhoc:~# wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
root@adhoc:~# chmod +x ec2.py ec2.ini
exporting some variables :
root@adhoc:~# export ANSIBLE_HOSTS=/etc/ansible/ec2.py
root@adhoc:~# export ANSIBLE_INI=/etc/ansible/ec2.ini
Now get all running Instances details info :
Important: make sure your ansible time is updated as per internet Time.
root@adhoc:/etc/ansible# /etc/ansible/ec2.py --list
{
"_meta": {
"hostvars": {
"52.41.118.0": {
"ansible_ssh_host": "52.41.118.0",
"ec2__in_monitoring_element": false,
"ec2_account_id": "904182454435",
"ec2_ami_launch_index": "0",
Checking Ping module if firewall is configured :
root@adhoc:/etc/ansible# ansible all -u ec2-user --private-key /home/adhoc/Downloads/class1.pem -m ping
52.41.118.0 | SUCCESS => {
"changed": false,
"ping": "pong"
}
Tip: you can add private key location using ssh-agent so you don't have to specify ssh-keys
root@adhoc:/etc/ansible# ssh-agent bash
root@adhoc:/etc/ansible# ssh-add ~/.ssh/keypair.pem
Now you can ping to all ec2 instances
[root@localhost ~]# ansible all -m ping -u ec2-user
[DEPRECATION WARNING]: ANSIBLE_HOSTS option, The variable is misleading as it can be a list of hosts and/or paths to
inventory sources . This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
13.126.182.236 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
Note: ping only specific tag machine
[root@localhost ~]# ansible -m ping -u ec2-user tag_ansible_machine[DEPRECATION WARNING]: ANSIBLE_HOSTS option, The variable is misleading as it can be a list of hosts and/or paths to
inventory sources . This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
13.126.182.236 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
root@adhoc:~# wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py
root@adhoc:~# wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
root@adhoc:~# chmod +x ec2.py ec2.ini
exporting some variables :
root@adhoc:~# export ANSIBLE_HOSTS=/etc/ansible/ec2.py
root@adhoc:~# export ANSIBLE_INI=/etc/ansible/ec2.ini
Now get all running Instances details info :
Important: make sure your ansible time is updated as per internet Time.
root@adhoc:/etc/ansible# /etc/ansible/ec2.py --list
{
"_meta": {
"hostvars": {
"52.41.118.0": {
"ansible_ssh_host": "52.41.118.0",
"ec2__in_monitoring_element": false,
"ec2_account_id": "904182454435",
"ec2_ami_launch_index": "0",
Checking Ping module if firewall is configured :
root@adhoc:/etc/ansible# ansible all -u ec2-user --private-key /home/adhoc/Downloads/class1.pem -m ping
52.41.118.0 | SUCCESS => {
"changed": false,
"ping": "pong"
}
Tip: you can add private key location using ssh-agent so you don't have to specify ssh-keys
root@adhoc:/etc/ansible# ssh-agent bash
root@adhoc:/etc/ansible# ssh-add ~/.ssh/keypair.pem
Now you can ping to all ec2 instances
[root@localhost ~]# ansible all -m ping -u ec2-user
[DEPRECATION WARNING]: ANSIBLE_HOSTS option, The variable is misleading as it can be a list of hosts and/or paths to
inventory sources . This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
13.126.182.236 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
Note: ping only specific tag machine
[root@localhost ~]# ansible -m ping -u ec2-user tag_ansible_machine[DEPRECATION WARNING]: ANSIBLE_HOSTS option, The variable is misleading as it can be a list of hosts and/or paths to
inventory sources . This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
13.126.182.236 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
Some tasks :
- Installing httpd software
root@adhoc:/etc/ansible# ansible all -s -u ec2-user --private-key /home/adhoc/Downloads/class1.pem -m yum -a "name=httpd state=present"
Note : here -s means sudo and -m for module
52.41.118.0 | SUCCESS => {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: priorities, update-motd, upgrade-helper\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.31-1.8.amzn1 will be installed\n--> Processing Dependency: httpd-tools = 2.2.31-1.8.amzn1 for package: httpd-2.2.31-1.8.amzn1.x86_64\n--> Processing Dependency: apr-util-ldap for package: httpd-2.2.31-1.8.amzn1.x86_64\n--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.31-1.8.amzn1.x86_64\n--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.31-1.8.amzn1.x86_64\n--> Running transaction check\n---> Package apr.x86_64 0:1.5.1-1.12.amzn1 will be installed\n---> Package apr-util.x86_64 0:1.4.1-4.17.amzn1 will be installed\n---> Package apr-util-ldap.x86_64 0:1.4.1-4.17.amzn1 will be installed\n---> Package httpd-tools.x86_64 0:2.2.31-1.8.amzn1 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.2.31-1.8.amzn1 amzn-main 1.2 M\nInstalling for dependencies:\n apr x86_64 1.5.1-1.12.amzn1 amzn-main 116 k\n apr-util x86_64 1.4.1-4.17.amzn1 amzn-main 87 k\n apr-util-ldap x86_64 1.4.1-4.17.amzn1 amzn-main 17 k\n httpd-tools x86_64 2.2.31-1.8.amzn1 amzn-main
Note : here -s means sudo and -m for module
52.41.118.0 | SUCCESS => {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: priorities, update-motd, upgrade-helper\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.31-1.8.amzn1 will be installed\n--> Processing Dependency: httpd-tools = 2.2.31-1.8.amzn1 for package: httpd-2.2.31-1.8.amzn1.x86_64\n--> Processing Dependency: apr-util-ldap for package: httpd-2.2.31-1.8.amzn1.x86_64\n--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.31-1.8.amzn1.x86_64\n--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.31-1.8.amzn1.x86_64\n--> Running transaction check\n---> Package apr.x86_64 0:1.5.1-1.12.amzn1 will be installed\n---> Package apr-util.x86_64 0:1.4.1-4.17.amzn1 will be installed\n---> Package apr-util-ldap.x86_64 0:1.4.1-4.17.amzn1 will be installed\n---> Package httpd-tools.x86_64 0:2.2.31-1.8.amzn1 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.2.31-1.8.amzn1 amzn-main 1.2 M\nInstalling for dependencies:\n apr x86_64 1.5.1-1.12.amzn1 amzn-main 116 k\n apr-util x86_64 1.4.1-4.17.amzn1 amzn-main 87 k\n apr-util-ldap x86_64 1.4.1-4.17.amzn1 amzn-main 17 k\n httpd-tools x86_64 2.2.31-1.8.amzn1 amzn-main
Great Article !! Thanks for sharing..
ReplyDeleteAzure DevOps Online Training
Microsoft Azure DevOps Training Courses
Microsoft Azure DevOps online Training in Hyderabad
Microsoft Azure DevOps Training
Azure DevOps Online Training in Hyderabad
very informative post.
ReplyDeleteDevops Training
Devops online Training
Devops Training in Hyderabad
ReplyDeleteThankyou for sharing Good information...
AWS Training
Hey thanks for this amazing post! Thank you so much for sharing the good post, I appreciate your hard work.Keep blogging.
ReplyDeleteDevOps Training in Electronic City
This is a very informative article. I found so many knowledgeable stuff in your blog especially its discussion. DevOps Training in Bangalore | Certification | Online Training Course institute | DevOps Training in Hyderabad | Certification | Online Training Course institute | DevOps Training in Coimbatore | Certification | Online Training Course institute | DevOps Online Training | Certification | Devops Training Online
ReplyDeleteThanks for one marvelous posting! I enjoyed reading it; you are a great author.
ReplyDeleteThanks for giving a great information about nice Article..
I have learned a lot from this
oracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
hadoop training in chennai
hadoop training in bangalore
Very Informative! To know more on best devops training.
ReplyDeleteVery Informative! To know more on devops engineer certification
ReplyDeleteThis article is a creative one and the concept is good to enhance our knowledge. Waiting for more updates.
ReplyDeleteDevops Online Course
JMeter Online Training
valuable blog,Informative content...thanks for sharing, Waiting for the next update…
ReplyDeleteGoogle Flutter and Dart Online Training
Flutter Online Courses
Valuable blog, Informative content...thanks for sharing, Waiting for the next update…
ReplyDeleteSpanish Language Classes in Chennai
Spanish Courses in Chennai
Really an informative blog...Thanks for sharing an informative article with us.
ReplyDeleteToefl Coaching in Madurai
Toefl Training in Madurai
Really an informative blog...Thanks for sharing an informative article with us.
ReplyDeleteFrench Classes in Bangalore
French Language Classes in Bangalore
Wonderful blog. Thanks for sharing a useful information.........
ReplyDeleteCloud Computing Courses in Chennai
Cloud Computing Online Course
ReplyDeleteNice to see this BLOG..keep updating More infromation Digital Lync offers one of the best Full Stack training in Hyderabad with a comprehensive course curriculum with Continuous Integration, Delivery, and Testing. Elevate your practical knowledge with quizzes, assignments, Competitions, and Hackathons to give a boost to your confidence with our hands-on Full Stack Training.
DevOps Training Institute
Python Training Institute
AWS Training Institute
Online Full Stack Developer Course Hyderabad
Python Course Hyderabad
Online AWS Training Course Hyderabad
devops training in hyderabad
angular training in hyderabad
Really nice blog. thanks for sharing such a useful information.
ReplyDeleteKotlin Online Course
Great blog.thanks for sharing such a useful information
ReplyDeleteInformatica Training in Chennai
This information really helped me a lot. It was very informative.
ReplyDeleteDevops Services
Great post. keep sharing such a worthy information
ReplyDeleteRPA Training in Chennai
RPA Training Online
RPA Training In Bangalore
Great post. Thanks for sharing such a useful blog.
ReplyDeletedot net training in Velachery
dot net training in Velachery
slot siteleri
ReplyDeletekralbet
betpark
tipobet
betmatik
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
E1M2BS
betmatik
ReplyDeletekralbet
betpark
mobil ödeme bahis
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
LBX3F
Thanks for sharing.
ReplyDeleteDevops course in Pune