Skip to main content

Secure nginx with Let's Encrypt on Ubuntu 18.04

Install and Configure Ansible on Ubuntu 16.04

in this article we will learn how to install and configure ansible in ubuntu 16.02, Ansible is a agent less configuration management tool which help us to manage large number of client machines easily, ansible running and communicates over ssh protocol, So it's doesn't need to install any software on client side.

Ansible Configuration management tool

Scenario : 

master server : / master
client server 1 : / slave1
client server 2 : / slave2
you can enter machine ip and name in /etc/host file. 

Installing the Ansible on Ubuntu 16.04 (we will install ansible on Master server only).
To install ansible you must have to configure PPA (Personal Package Archive) on your system for latest version of ansible.

$sudo apt-add-repository ppa:ansible/ansible
Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.
 More info:
Press [ENTER] to continue or ctrl-c to cancel adding it
gpg: keyring `/tmp/tmpb9i7viln/secring.gpg' created
gpg: keyring `/tmp/tmpb9i7viln/pubring.gpg' created
gpg: requesting key 7BB9C367 from hkp server
gpg: /tmp/tmpb9i7viln/trustdb.gpg: trustdb created
gpg: key 7BB9C367: public key "Launchpad PPA for Ansible, Inc." imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

After add PPA to server you will have to update server using below command.
$sudo apt-get update
Get:1 xenial InRelease [18.0 kB]
Hit:2 xenial InRelease
Get:3 xenial-updates InRelease [109 kB]
Get:4 xenial-security InRelease [107 kB]
Get:5 xenial/main amd64 Packages [536 B]
Get:6 xenial-backports InRelease [107 kB]
Get:7 xenial-updates/main amd64 Packages [767 kB]
Get:8 xenial/main i386 Packages [536 B]
Get:9 xenial/main Translation-en [344 B]

Finaly install ansible using below command.
$sudo apt-get install ansible

Finding Ansible version
# ansible --version
ansible 2.5.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]

Ansible Hosts Configuration : 
ansible requires information of remote machine name and ip addresses, this all information are stored in host file. default path of file is  /etc/ansible/hosts. we can edit it or create new one also. append ip or name of server in host file. 
 $vim /etc/ansible/hosts

and save the file.

we need to setup ssh keys and copy in all client machine. so they can communicates each other without asking password.

Click here To configure password less login between server and client using ssh.

Executing the Simple Ansible Commands : 
First we will check ping command, and run below command  which ping client machine which we have defined in /etc/ansible/host file.

root@master:~# ansible -m ping servers
slave2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
slave1 | SUCCESS => {
    "changed": false,
    "ping": "pong"


Success means all client machines can communicates with server.

We can use " shell module to run a terminal command from the Anisble remote hosts and retrive the results.
Let's find out memory usage of all client machine. run below command to check memory usage of all ansible clinet machine.

$ ansible -m shell -a "free -m" servers

slave1 | SUCCESS | rc=0 >>
              total        used        free      shared  buff/cache   available
Mem:            990         155         170          14         663         648
Swap:          1905           0        1905

slave2 | SUCCESS | rc=0 >>
              total        used        free      shared  buff/cache   available
Mem:            990         159         170          14         660         646
Swap:          1905           0        1905

You can see the output of memory utilization.

To check disk usage of all out ansible client with below command.
$ ansible -m shell -a "df -h" servers

slave1 | SUCCESS | rc=0 >>
Filesystem      Size  Used Avail Use% Mounted on
udev            474M     0  474M   0% /dev
tmpfs           100M   11M   89M  11% /run
/dev/sda1       5.4G  3.9G  1.2G  77% /
tmpfs           496M  188K  495M   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           496M     0  496M   0% /sys/fs/cgroup
/dev/sda5       268M   62M  189M  25% /boot
tmpfs           100M   32K   99M   1% /run/user/108
tmpfs           100M     0  100M   0% /run/user/0

slave2 | SUCCESS | rc=0 >>
Filesystem      Size  Used Avail Use% Mounted on
udev            474M     0  474M   0% /dev
tmpfs           100M   11M   89M  11% /run
/dev/sda1       5.4G  3.9G  1.3G  77% /
tmpfs           496M  188K  495M   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           496M     0  496M   0% /sys/fs/cgroup
/dev/sda5       268M   62M  189M  25% /boot
tmpfs           100M   32K   99M   1% /run/user/108
tmpfs           100M     0  100M   0% /run/user/0

You can check the any service status or restart any service using below command on all ansible client.

$ansible -m shell -a "service sshd restart " servers
slave2 | SUCCESS | rc=0 >>

slave1 | SUCCESS | rc=0 >>

To check uptime of all ansible clients : 

$ ansible -m shell -a "uptime" servers

slave1 | SUCCESS | rc=0 >>
 13:19:49 up 10 days, 23:28,  1 user,  load average: 0.00, 0.00, 0.00

slave2 | SUCCESS | rc=0 >>
 13:19:46 up 10 days, 23:28,  1 user,  load average: 0.00, 0.00, 0.00

To check process of any ansible client :

$ ansible -m shell -a "ps -aux | grep ssh " slave1

slave1 | SUCCESS | rc=0 >>
root     10307  0.0  0.5  65512  5388 ?        Ss   13:11   0:00 /usr/sbin/sshd -D
root     10414  0.2  0.7  95196  7280 ?        Ss   13:21   0:00 sshd: root@pts/8
root     10519  0.0  0.0   4508   716 pts/8    S+   13:21   0:00 /bin/sh -c ps -aux | grep ssh
root     10521  0.0  0.0  21292   920 pts/8    S+   13:21   0:00 grep ssh

here we have checked process of ssh of slave1 server.

To check any files from remote ansible client : 

$ansible -m shell -a "cat /etc/timezone" slave1

slave1 | SUCCESS | rc=0 >>

To check CPU info of client machine.

$ansible -m shell -a "cat /proc/cpuinfo" slave1

slave1 | SUCCESS | rc=0 >>
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 63
model name      : Intel(R) Xeon(R) CPU E5-2609 v3 @ 1.90GHz
stepping        : 2
cpu MHz         : 1899.999
cache size      : 15360 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 15
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq monitor ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm fsgsbase avx2 invpcid
bugs            :
bogomips        : 3799.99
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

So in this article we have learn how to configured ansible server and clients. So in next article i will explain you to how to create and run ansible playbooks. 



Popular posts from this blog

Another instance of Certbot is already running - Solved - Linux guru

Error : Another instance of Certbot is already runningcertbot --server --manual --preferred-challenges dns --installer nginx -d * Another instance of Certbot is already running Reason : when you run certbot form your machine and unexpectedly stop the command, Then cert bot is not running but it left some .certbot.lock files behind.You need to kill the certbot instance form your machine. Solution : Run the below command to find killed certbot.find / -type f -name ".certbot.lock" You can see result of the command, If there are, you can remove them. Run below command to remove them.find / -type f -name ".certbot.lock" -exec rm {} \; And try again.

Install Apache Using Ansible Playbooks

Ansible is a automation tool which is widely used, you can install and install, configure and manage number of system and services remotely. you can install software and manage services and tasks without needing manually log in to each servers. you have to install ansible in one machine and use ssh to communicate host each other.

Ansible uses Playbooks which is written in YAML format. it's uses module base format. with playbook can run multiple tasks at time and provide more advance functionality, YAML file always start with "---" syntax. In this article we will see how to install and configure apahce2 using ansible YAML script. Master server : [Ansible server, ] Slave 1 : [need to install apache2 in slave 1] Slave 2 : [need to install apache2 in slave 2] We need to configure slave server info in our ansible configuration file, click here to know how to add client machine to ansible. Let's update our apache2.yml file and install…

Create aws s3 bucket using cli

In this article i will explain you to how to manage s3 bucket and objects using AWS cli command line interface. for that you will have to configure AWS cli interface to your local linux machine. You can configure cli from. HERE.

After configured aws cli to your local machine, you can run all below commands. How to create bucket using AWS Cli.root@master:~# aws s3 mb s3://linuxgurubucket make_bucket: linuxgurubucket Listing Bucket : To list all bucket : root@master:~# aws s3 ls 2018-05-01 15:28:37 linuxgurubucket To list all objects from bucket :root@master:~# aws s3 ls s3://linuxgurubucket 2018-05-01 15:32:16 71515 vishal.jpg How to copy local file to s3 using aws cp command :root@master:~# aws s3 cp s3://linuxgurubucket/ upload: ./ to s3://linuxgurubucket/ To check it's upload or not :root@master:~# aws s3 ls s3://linuxgurubucket/ 2018-05-01 15:34:19 82 2018-05-01 15:32:16 71515 vishal.jpg To remove file from s3 bucket using cli: