Ansible is a radically simple IT automation system. It handles configuration-management, application deployment, cloud provisioning, ad-hoc task-
execution, and multinode orchestration – including trivializing things like zero downtime rolling updates with load balancers.
Step 1: Install Ansible
On Debian based systems:
apt-get insatll ansible -y
On RPM Based systems
yum install ansible -y
Ansible config files:
# ls -l /etc/ansible/ total 16 -rw-r--r-- 1 root root 10301 Jan 14 2017 ansible.cfg -rw-r--r-- 1 root root 995 Jan 17 01:59 hosts
Ansiable works on password less ssh, No client side configuration required, you only have to setup password less ssh from server to clients. Follow below steps to setup password less access.
Step 2: On Ansible server generate ssh key
Run ssh-keygen command to create new ssh key hit enter for default file location do not add passphrase when asked leave it blank and hit enter.
[root@server]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: df:24:ac:c5:7d:5f:0c:ca:8d:17:c2:92:25:3a:80:45 root@server The key's randomart image is: +--[ RSA 2048]----+ | E | | . | | . . | | o = o = o | |. . . S B A + o| | . . . * = o ..| | o . . . .| | . | | | +-----------------+
.ssh directory get created inside roots home directory
# ls ~/.ssh/ id_rsa id_rsa.pub
Step 3 : Copy ssh key on Ansible clients
Copy id_rsa.pub key on clients.
# scp ~/.ssh/id_rsa.pub root@client:~/.ssh/authorized_keys
Ansible is now ready to do its magic.
“/etc/ansible/hosts” is default ansible ‘hosts’ file. Edit it and add ipaddress of your clients at the file or you can create host groups
# Ex 1: Ungrouped hosts, specify before any group headers.
green.example.com blue.example.com 192.168.100.1 192.168.100.10
# Ex 2: A collection of hosts belonging to the ‘webservers’ group
[webservers] alpha.example.org beta.example.org 192.168.1.100 192.168.1.110
On this example we have this:
cat /etc/ansible/hosts|tail -n3 10.192.80.31 [webservers] 10.192.80.31
Step 4 : Run ansible
~# ansible -m ping 10.192.80.31 10.192.80.31 | SUCCESS => { "changed": false, "ping": "pong" }
For individual client:
root@puppet:~# ansible -m shell -a "ps -ef|grep named" 10.192.8.31 10.192.8.31 | SUCCESS | rc=0 >> root 1481 1 0 Jun17 ? 00:00:00 /usr/local/sbin/named -c /etc/named.conf root 5774 5773 0 03:21 pts/2 00:00:00 /bin/sh -c ps -ef|grep named
For webservers group:
root@puppet:~# ansible -m shell -a "ps -ef|grep httpd" webservers 10.192.8.31 | SUCCESS | rc=0 >> root 1379 1 0 Jun17 ? 00:00:01 /usr/sbin/httpd git 5616 1379 0 03:17 ? 00:00:00 /usr/sbin/httpd git 5617 1379 0 03:17 ? 00:00:00 /usr/sbin/httpd
Warning: count(): Parameter must be an array or an object that implements Countable in /home/vhosts/howtolinuxblog.orgfree.com/wp-includes/class-wp-comment-query.php on line 399
MOST COMMENTED
Uncategorized
Ubuntu 16.04 No desktop only shows background wallpaper
Administration / DNS / Linux
Dig command examples
Virtualization
OpenVz(Kernel Base Open source Virtulization)
Uncategorized
Install Ansible on Linux
Puppet
Configuring puppet4 server agent and puppetdb on ubuntu16.04
Database
Installing postgresql on ubuntu 16.04
Puppet
opensource puppet4 installation on ubuntu16.04