Ansible Full Documentation
Ansible Full Documentation
Ansible Full Documentation
=========================
#cd .ssh/
#ssh-keygen
id_rsa id_rsa.pub
In clients
============
python need to install in nodes
13.vi /etc/ssh/sshd_config open this file and do the following changes
Permitrootlogin yes
passwordauthentication yes
:wq!
14.service sshd restart
15.We need to crete a password for the clients
16.passwd root
type ur passwd
17.service sshd restart
In server
=========
16.execute the foolowing command
ssh-copy-i root@ip of clients or ssh-copy-id (client id)
#ssh (clientid) ---control enters into the client and enter exit to come out of
node
To test the connection
Ansible all -m ping (response comes from node as pong)
===================================================================================
=====================
18.Now we need to write the playbooks and apply to the nodes
19.mkdir playbooks
20.cd playbooks
21.vi file.yml
---
- hosts: dev test
tasks:
- name: create directory on tmp dir for clients
file: path=/tmp/mouni state=directory
- name: create file on mouni dir for clients
file: path=/tmp/mouni/hanu state=touch
:wq!
Ansible ad-hoc commands (by using this commands we cannot write a playbook, by
using single command we create a file,directory etc..)
===========================================================
25.ansible all -m file -a "dest=/tmp/a.txt state=touch mode=600" //cmd to create a
file using ad-hoc cmd//
26.ansible all -m file -a "dest=/tmp/mouni/suni state=directory" //cmd to create a
directory//
27.ansible dev -m yum -a "pkg=git state=installed" //instation of package in dev
group//
ansible_server | SUCCESS => {
"cache_update_time": 1514874149, //We will see this msg//
"cache_updated": false,
"changed": false
}
28.ansible test -m copy -a "src=/root/devops.txt dest=/root" //copy the file from
test group//
29.vi ansible.conf
30.In this we need to uncomment the log-path = /var/log/ansible.log //this the
ansible log file path//
31.when we execute this we can see the logs on this file
Ansible when command
=====================
32.cd playbooks
33.vi when.yml
---
- hosts: all
tasks:
- name: create file for redhat family
file: path=/tmp/chef1 state=touch mode=0777
when: ansible_os_family == "RedHat"
ignore_errors: true
- name: create directory for debian family
file: path=/tmp/jenkins1 state=directory
when: ansible_os_family == "Debian"
ignore_errors: true
:wq!
34.In redhat client go to /tmp/ directory we can see chef1 directory and in debian
family we can see jankins1 directory
Ansible loops and conditions
=============================
35.using this loop we are creating the multiple users
---
- hosts: all
tasks:
- name: add several users
user:
name: "{{ item.name }}"
state: present
groups: "{{ item.groups }}"
with_items:
- { name: 'mounika', groups: 'root' }
- { name: 'mounika1', groups: 'root' }
:wq!
36.Now we the two user are created.Go to vi /etc/passwd
here we can see the users which we are created
Ansible vault
=============
By using this we can secure our playbook in the form of encryption
36.root@ansible-server:/etc/ansible/playbooks# ansible-vault create test.yml
New Vault password:
Confirm New Vault password:
vi test.yml
37.we will get this encrpted file
$ANSIBLE_VAULT;1.1;AES256
34346331323232653032666463373335623665663133613764653763336163396265343437326236
3933343133323363613337353333663764663537336235310a326239643732633935366265646332
61623632653731373036353239643435373838373338306339343964663166343033306632623063
3063636538343731650a366263373531306430643064633039336663633435346436313233343238
63636633663133336230636638383166646637663661353761663761316266663736313765393661
31623162393339326433643230633163306133383465613664313236353065666361333732633861
61306466396334313534316634376663393634646264383765616632646530633762353432313436
30366162316335666463616265366230343664323339303062396464643236383363633435376633
30323565383934663762313337383966346133356161306261363734633431366235633062373334
6234303832623833353831646465396137353466663831396466
---
- hosts:
tasks:
- name: fetching devops.txt from clients
fetch: src=/https/www.scribd.com/root/devops.txt dest=/etc/ansible
---
- hosts:
tasks:
- name: fetching devops.txt from clients
fetch: src=/https/www.scribd.com/root/devops.txt dest=/etc/ansible
Ansible role
=============
Roles are ways of automatically loading certain var files,tasks,and handlers based
on a known file structure.Grouping content by roles also allows easy sharing of
roles with other users.
Roles are just automation around 'include' directives as describe
above