0% found this document useful (0 votes)
37 views2 pages

Ansible Lab - Day 1

This document outlines the setup of Ansible across three machines - a master workstation and two servers - to perform configuration management. It describes creating a user, editing hosts files, installing Ansible on the workstation, generating SSH keys, and configuring Ansible to connect to the servers via inventory and privilege escalation. The document provides example commands to test the Ansible connection and execute commands on the servers.

Uploaded by

abobakr gamal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Ansible Lab - Day 1

This document outlines the setup of Ansible across three machines - a master workstation and two servers - to perform configuration management. It describes creating a user, editing hosts files, installing Ansible on the workstation, generating SSH keys, and configuring Ansible to connect to the servers via inventory and privilege escalation. The document provides example commands to test the Ansible connection and execute commands on the servers.

Uploaded by

abobakr gamal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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
[email protected]
[devops@workstation ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub
[email protected]
[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