Ansible

Ansible

Let's start with your journey on Ansible !!

  1. How to Create a Server in AWS?

  2. How to get into the server?

  3. How to Create users in linux?

  4. Make normal users as sudoer Ssh password authentication?

  5. CM

  6. Ansible :

We can execute any linux commands

$ sudo -i

# apt-get update

# apt-get install apache2 ( it is web sever)

# adduser sagar ( sagar is normal user)

# su sagar

$ cd

$ pwd

$ touch f1 f2 f3

$ ls

$ ls -la

$ mkdir myfolder

$ ls

$ apt-get install apache2

I want to install apache2 by sagar user.

By making suuser as sagar, by giving root privilege to sagar

# visudo

sagar ALL=(ALL) NOPASSWD: ALL

Ctr+x , press y , press enter

# su sagar

# sudo apt-get install apache2

Passwordless Authentication?

Configure master server

  1. Create a Aws ubuntu 18 server with t2.micro

  2. Add sagar user

# adduser sagar

  1. Make sagar user as sudoer

# visudo

sagar ALL=(ALL) NOPASSWD: ALL

ctr+x, press y and enter

  1. Passwd authentication( with passwd without pem )

# vi /etc/ssh/sshd_config

Passwd authentication yes

Shift+:wq

  1. Restart ssh service

# service ssh restart

Configure Node servers

  1. Create a Aws ubuntu 18 server with t2.micro

  2. Add sagar user

# adduser sagar

  1. Make sagar user as sudoer

# visudo

sagar ALL=(ALL) NOPASSWD: ALL

ctr+x, press y and enter

  1. Passwd authentication( with passwd without pem )

# vi /etc/ssh/sshd_config

Passwd authentication yes

Shift+:wq

  1. Restart ssh service

# service ssh restart

Communication master server to nodes server without passwd ON MASTER SERVER as Sagar User

  1. su sagar

  2. $ cd

  3. $ pwd

  4. $ ssh-keygen ( by this command , will generate private and public key)

  5. $ ssh-copy-id <private ip of nodes>

  6. $ ssh <private ip of nodes>

( without pem and passwd , we can able to connect master into nodes)

CM:

Ansible: PUSH Model

Install and configure ansible master

  1. Create aws ubuntu 18 server

  2. Add ansible user

# adduser maha

  1. Make ansible user as sudoer

# visudo

Maha ALL=(ALL) NOPASSWD: ALL

Ctr+x, press y and enter

  1. Passwd authentication( with passwd without pem)

# vi /etc/ssh/sshd_config

Passwd authentication yes

Shift:wq and enter

  1. Restart ssh service

# service ssh restart

  1. Install ansible

# sudo apt-add-repository ppa:ansible/ansible

# sudo apt update

# sudo apt install ansible

# ansible --version

Configure ansible nodes

  1. Create aws ubuntu 18 server

  2. Add ansible user

# adduser maha

  1. Make ansible user as suduser

# visudo

Maha ALL=(ALL) NOPASSWD: ALL

Ctr+x, press y and enter

  1. Passwd authentication( with passwd without pem)

# vi /etc/ssh/sshd_config

Passwd authentication yes

Shift:wq and enter

  1. Restart ssh service

# service ssh restart

  1. Don’t Install ansible

# sudo apt-add-repository ppa:ansible/ansible

# sudo apt update

# sudo apt install ansible

# ansible --version

Connect ansible master to ansible nodes without passwd ON ANSIBLE MASTER as Ansible user as maha

  1. su maha

  2. $ cd

  3. $ pwd

  4. $ ssh-keygen

  5. $ ssh-copy-id <private ip of ansible node>

  6. $ vi myhost

<private ip of ansible node1>

<private ip of ansible node2>

<private ip of ansible node100>

:wq!

  1. ansible all -i myhost -m ping