Friday, 2 August 2019

How to install Ansible on Amazon ec2 server by Raj Gupta

Note:- The user created in Master and all client server must be same let say in my case ansible in master and in all client server.

Fist setup password less SSH between master and all client by using below step:-(User name must be same in both )

https://rajguptaaws.blogspot.com/2019/03/ssh-login-without-password-by-raj.html

Now run the below command in Master Server

[ansible@ip-172-31-36-60 ~]$ sudo yum-config-manager --enable epel
[ansible@ip-172-31-36-60 ~]$ sudo yum install ansible
[ansible@ip-172-31-36-60 ~]$ ansible --version
[ansible@ip-172-31-36-60 ~]$ sudo vi /etc/ansible/hosts
[webservers]
172.31.90.234

Now test it.

[ansible@ip-172-31-36-60 ~]$ ansible all -m ping
172.31.90.234 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[ansible@ip-172-31-36-60 ~]$

-----------------------------------------------------------------------------------------------------------------

How to run ansible by using custom inventory file in place of default inventory file(/etc/ansible/hosts
)

Step 1:-  Comment the line in default inventory file(/etc/ansible/hosts)

[ansible@ip-172-31-36-60 ~]$ sudo vi /etc/ansible/hosts
#[webservers]
#172.31.90.234

Step 2: create own custom inventory file( name you can give any thing)

[ansible@ip-172-31-36-60 ~]$ vi inventory.txt
[ansible@ip-172-31-36-60 ~]$ cat inventory.txt
[webservers]
172.31.90.234


Now test it:-

[ansible@ip-172-31-36-60 ~]$ ansible all -m ping -i inventory.txt
172.31.90.234 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

You can also use the below option

[ansible@ip-172-31-36-60 ~]$ ansible webservers -m ping -i inventory.txt
172.31.90.234 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[ansible@ip-172-31-36-60 ~]$ ansible webservers* -m ping -i inventory.txt
172.31.90.234 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[ansible@ip-172-31-36-60 ~]$ ansible webserve* -m ping -i inventory.txt
172.31.90.234 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[ansible@ip-172-31-36-60 ~]$ ansible 172.31.90.234 -m ping -i inventory.txt
172.31.90.234 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[ansible@ip-172-31-36-60 ~]$

No comments:

Post a Comment