0% found this document useful (0 votes)
13 views

Ansible

1) This document provides instructions for setting up an Ansible master server and client for configuration management. 2) Key steps include installing Ansible on the master, adding an Ansible user, editing SSH configs to allow password-less SSH, generating SSH keys, and editing inventory files to add client IPs. 3) The document also demonstrates various ad-hoc Ansible modules like ping, shell, copy, file, and yum that can be run from the master to configure clients. It introduces the concept of groups in inventory files and playbooks as a way to organize and run tasks on clients.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Ansible

1) This document provides instructions for setting up an Ansible master server and client for configuration management. 2) Key steps include installing Ansible on the master, adding an Ansible user, editing SSH configs to allow password-less SSH, generating SSH keys, and editing inventory files to add client IPs. 3) The document also demonstrates various ad-hoc Ansible modules like ping, shell, copy, file, and yum that can be run from the master to configure clients. It introduces the concept of groups in inventory files and playbooks as a way to organize and run tasks on clients.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Ansible-Master server

======================
************************
======================
1)sudo su===>Change to root
2)Whoami==>To check the User
3)python –version==>To check the python version in master
4)yum install ansible==>To install ansible
(or)
sudo amazon-linux-extras install ansible2 ==>for amazon-linux
5)ansible - -version==>To check the version of ansible
6)useradd ansible
7)passwd ansible
8)visudo==>without a passwd=>ansible ALL=(ALL) NOPASSWD: ALL
9)vim /etc/ssh/sshd_config==>Enable passwordAuthentication
10)service sshd status
11)service sshd restart
12)su – ansible

commands to execute As ansible admin

13)pwd===>(/home/ansible)
14)ssh-keygen==>Hit enter for everything
15)cd .ssh==>((id-rsa id_rsa.pub))
16)ssh-copy-id 13.233.128.22==>Establish connection between master and client
(it will generate know_hosts it contains key)
17)cd /etc/ansible/==>
ansible.cfg==>main configuration file
hosts==>Inventory file
roles(d)
18) sudo vim hosts=>copy client ip address

19)ansible all -m ping


20)ansible 15.206.74.184:15.206.74.184 -m ping==>to ping multiple clients

groups in hosts file


================
[groupname]
15.206.74.184
15.206.74.182
15.206.74.189

Group of Groups
============
[ggroup:children]
group1
group2
group3

21)ansible ggroup -m ping


22)ansible all -m ping -i host1==>for customised inventory file
23)ansible all -m shell -a “uptime”===>uptime from client
24)ansible all -m copy -a “src=./hosts dest=/tmp/”==>copy files
25)ansible all -m file a “path=/tmp/xyx.txt state=touch mode=777”
==>To create a file in client with permissions
26)ansible all -m file a “path=/tmp/xyx.txt state=touch ”
==>To create a file in client without permissions
27)ansible all -m file a “path=/tmp/xyx.txt state=absent”
==>To delete the file in client
28)ansible all -m file a “path=/tmp/xyx state=directory”
==>To create a directory in client
29)ansible-doc -l==>for ansible documentation
30)ansible-doc -l | wc -1===>3387 modules in ansible
31)ansible all -m yum -a “name=httpd state=present” -b
=>to install package in ansible client(Ad-hoc)
32) ansible all -m yum -a “update”
(or)
ansible all -m shell -a “yum update”
(or)
ansible all -m command -a “yum update”

33)ansible all -m fetch -a “path=src=/tmp/xyz.txt dest=/tmp/abc.txt ” -b==>Download file from


client to master
34)
================
Ansible-Client server
================
1)python - - version
2)useradd ansible
3)passwd ansible
4)visudo==>without a passwd=>(ansible ALL=(ALL) NOPASSWD: ALL)
5)vim /etc/ssh/sshd_config==>Enable passwordAuthentication
6)service sshd restart
7)whereis httpd (or) which httpd(location=>/sbin/httpd)

Two ways to interact with client nodes

1)Ad-hoc commands(Single line commands)


2)playbook==>Script for ansible
ansible is a idempotency

“.yaml/.yml===>yet another markup language

structure of playbook
==================
---
- hosts: all
become: yes
tasks:
- yum: name=php state=present
- yum: name=java state=present

You might also like