You are on page 1of 2

Ansible Lab - Day 1

We have Three Machines ( Master [workstation.lab.example.com] [172.25.250.128]


Server1 [servera.lab.example.com] [172.25.250.130]
Server2 [serverb.lab.example.com] [172.25.250.129])
1- On All Machines
-create the user devops on all three machines (useradd and passwd)
-edit /etc/hosts and add these lines:
172.25.250.128 workstation.lab.example.com
172.25.250.130 servera.lab.example.com
172.25.250.129 serverb.lab.example.com
-

2- On Master :
[root@workstation ~]# yum clean all
[root@workstation ~]# yum repolist
[root@workstation ~]# yum epel-release
[root@workstation ~]# yum install ansible -y
[root@workstation ~]# su - devops
[devops@workstation ~]$ ssh-keygen
[devops@workstation ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub
devops@172.25.250.129
[devops@workstation ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub
devops@172.25.250.130
[devops@workstation ~]$ mkdir /project1
[devops@workstation ~]$ cd project1/
[devops@workstation project1]$ vi /tmp/inventory and add
172.25.250.130
172.25.250.129

[devops@workstation project1]$ vi ansible.cfg and add


[defaults]
inventory = /tmp/inventory
[privilege_escalation]
become = true
become_method = sudo
become_user = root
become_ask_pass = no
3- On Server1 and Server2 :
[root@servera ~]# vi /etc/sudoers and add in line 101
(:set number to see numbers in file)
devops ALL=(ALL)
NOPASSWD: ALL

4- On Master :
[devops@workstation project1]$ ansible all --list-hosts you should
see the ips you added in /tmp/inventory
[devops@workstation project1]$ ansible all -m command -a idwill execute id
command on the servers and return the answers

at this point lab is finished.

explore
[devops@workstation project1]$ ansible all -m command -a id -v will
show you where the conf file used to connect to hosts + execute the command
[devops@workstation project1]$ ansible all -m command -a id --become will
force become = true when executing ( when become = false in ansible.cfg )

You might also like