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

Ansible Notes

Uploaded by

Shyam Duvvapu
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Ansible Notes

Uploaded by

Shyam Duvvapu
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 19

Ansible Overview

How ansible works?


===================================================================================
Pre-requisite between controller and target node for passwordless connection
Installation of Ansible
Modules using Adhoc commands
===================================================================================
Inventory
Playbooks
Variables
===================================================================================
Tags
Registers
===================================================================================
Handlers
Loops
===================================================================================
Templates
Roles
E2E playbook for httpd server
E2E playbook for Tomcat server
===================================================================================
Tips and Tricks of Ansible
Ansible Integration with Jenkins
===================================================================================
=======================================
Ansible: Ansible is an automation tool or configuration management tool used for
automating the manual task without human intervention.
Ansible provides automation for installations, uninstallation, validations,
complex configuration changes etc
Ansible helps in re-using yaml files for the installation,uninstallation,
validations etc.
Ansible also provides integration with jenkins for further reducing effort of
running the commands in command line interface.
Ansible uses linux commands for all the ansible activities.
===========================================================================
Why Ansible ?
===========================================================================

eg: Install Maven in 100 Machine:

1. Login into machine


2. Install java - yum install java-1.8.0* -y
3. Download the maven tar file - wget <URL>
4. Extract tar file - tar -xvf maven-3.6.3.tar.gz
5. set the path for maven and java - /etc/profile.d/maven.sh
6. java -version and mvn --version
7. logout the machine.

eg: Uninstall Maven in 100 Machine:

1. Login into machine


2. Uninstall java - yum remove java-1.8.0* -y
3. unset the path for maven and java - /etc/profile.d/maven.sh
4. Delete the maven direcrtory
5. verify java -version and mvn --version
6. logout the machine.

Challenges:
1. Human effort
2. Can lead to human errors
3. Time consuming task
4. Efforts can be re-used - No reuseablity
5. At Runtime , Application may be break.
===================================================================================
======================================
How ansible works?
===================================================================================
======================================
Ansible uses push mechansim which is based on passwordless connection.
Ansible is agentless mechansim ie it doesnt require any agent to be installed in
target nodes.
Ansible works on 2 tier architecture ie Ansible controller and Ansible target
nodes.
Ansible controller -> Ansible target
Ansible playbooks - yamls

===================================================================================
===============
Alternate Configurtion management tools:
===================================================================================
===============
Puppet - pull mechanism - agent -> puppet agent is required to installed puppet
machines.
puppet workstation -> puppet master -> puppet nodes(agent)
puppet manifest -> yamls
3 tier architecture
===================================================================================
===============
chef - pull mechanism - agent -> chef client is required to installed chef nodes
Chef cookbooks -> yamls
3 tier architecture
===================================================================================
==========
Pre-requisite between controller and target node for passwordless connection
===================================================================================
==========
1. Ansible user/password on both controller and target nodes
sudo su
useradd ansible
passwd ansible

2. visudo - delegate privilages on both controller and target nodes


Add under root and #wheels user
ansible ALL=(ALL) PASSWD: ALL

3.Enable ssh configuration on both controller and target nodes:

vi /etc/ssh/sshd_config
PermitRootLogin yes
PAsswordAuthentication yes

systemctl restart sshd

4. Exit from root user and switch to ansible user on both controller and target
nodes
exit
su - ansible

5. SSH KEy Generation on both controller and target nodes:

a. ssh-keygen -t rsa

b. cd .ssh
cat id_rsa.pub > ~/.ssh/authorized_keys

c. Copy the public ssh key vice versa.


ssh-copy-id ansible@destination-IP

d. login vice versa without password.

============================================================================
Ansible Installation only on Master/controller :
============================================================================
1. Install wget:
sudo yum install wget -y

2. Ansible installation steps:


sudo wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo rpm -ivh epel-release-latest-7.noarch.rpm
sudo yum install ansible -y
ansible --version

3. Configuration setup:
/etc/ansible/ansible.cfg

4. Ansible host file:


/etc/ansible/hosts --> mention your target nodes.
sudo vi /etc/ansible/hosts -> default inventory

[webservers]
Private-IP-of-target-Node

====================================================================
Verify if target machine is reachable:
====================================================================
ansible webservers -m ping

[ansible@ip-172-31-2-51 ~]$ ansible webservers -m ping


172.31.9.124 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
[ansible@ip-172-31-2-51 ~]$
===================================================================================
====================
Inventories : default /etc/ansible/hosts
customize /home/ansible/inventory

command : ansible webservers -m ping // default inventory is called ie


/etc/ansible/hosts
ansible webservers -i inventory -m ping //customized inventory is
called ie "inventory"
===================================================================================
====================
Modules using Adhoc commands:
Ansible Modules are triggered by adhoc command.

syntax : ansible hostname/hostgroup -i /path/to/inventory -m module_name -a


arguments --become
===================================================================================
====================
1. setup: setup module is used for gathering all the information about target nodes
like OS related info, network info, resources information, Disk details etc

command: ansible webservers -i inventory -m setup


==========================================================================
2. ping : Ping module is used for checking the connectivity between controller and
target nodes.

command: ansible webservers -i inventory -m ping


==========================================================================
3. command : Command module is used for running all linux commands.

command: ansible webservers -i inventory -m command -a "ls -lrt"


ansible webservers -i inventory -m command -a "mkdir test"
==========================================================================
4. Shell : Shell module is also used for running all linux commands and provides
flexibility to run shell scripts

command: ansible webservers -i inventory -m shell -a "ls -lrt"


ansible webservers -i inventory -m shell -a "mkdir test"
ansible webservers -i inventory -m shell -a "bash startup.sh"

===================================================================================
================
5. user : User module is used for creating user in linux.

command: ansible webservers -i inventory -m user -a 'name=john state=present' --


become
ansible webservers -i inventory -m user -a 'name=john state=absent' --
become
--become - sudo privileges
===================================================================================
================
6. file: File module is used for creating files and directories in linux

=======================================
Create file and directory:
=======================================

command: ansible webservers -i inventory -m file -a 'dest=/home/ansible/file.txt


state=touch mode=755 owner=root group=root' --become

command: ansible webservers -i inventory -m file -a 'dest=/home/ansible/test_dir


state=directory mode=775 owner=root group=root' --become

=======================================
Delete file and directory:
=======================================

command: ansible webservers -i inventory -m file -a 'dest=/home/ansible/file.txt


state=absent' --become

command: ansible webservers -i inventory -m file -a 'dest=/home/ansible/test_dir


state=absent' --become
===================================================================================
========================
7. software module : yum module is used for installation and uninstallation of
packages

command: ansible webservers -i inventory -m yum -a 'name=httpd state=present' --


become
ansible webservers -i inventory -m yum -a 'name=httpd state=absent' --
become
ansible webservers -i inventory -m yum -a 'name=httpd state=latest' --
become

===================================================================================
=============================
8. service module: Service module is used starting the service of the package or
application.

command: ansible webservers -i inventory -m service -a 'name=httpd state=started'


--become
ansible webservers -i inventory -m service -a 'name=httpd state=stopped'
--become
ansible webservers -i inventory -m service -a 'name=httpd state=restarted'
--become
===================================================================================
=============================
9. copy: Copu module is used for copying the files from controller to target nodes.

command: ansible webservers -i inventory -m copy -a 'src=/home/ansible/machine-


controller.txt dest=//home/ansible/machine-controller.txt' --become

===================================================================================
========================
Inventory :
===================================================================================
========================
Inventory is a file which contains all the target nodes
IP-Address/hostname/hostgroups.
With help inventory file , Ansible controller connects to target machines.

=========================
Types of Inventories :
=========================
1. INI format : File is based format which doesnt require any indentations ie
proper spaces and INI format inventory does not have any extension.

eg: inventory , inventory_frontend, inventory_backend, inventory-data-engineering


etc

================
vi inventory
===============
#ungrouped servers
10.0.0.24
db-server-01
backend-application-server

#grouped servers
[webservers]
10.0.0.54
webservers-01
webservers-02
webservers-03
webservers-[10-20]

[appservers]
appservers-[1-10]

[prod-dbservers]
10.0.43.65
172.32.23.24
===========================================
2. YAML format: Yaml format inventory is indentation based inventory which requires
proper spaces and also it has extension as .yml/yaml.

eg: inventory.yml, inventory-tomcat.yml etc

===============================
vi inventory.yml
===============================
all:
hosts: // ungrouped servers
10.0.0.24
db-server-01
backend-application-server
children:
hosts:
webservers: // grouped servers
webserver-01
webservers-[101-110]
appservers: // grouped servers
10.0.0.23
app-server-10
app-server-[1-4]

===================================================================================
=======================================
Ansible Playbook:
===================================================================================
==================================
Playbook is instruction file where all script/code is written in yaml format for
running linux commands, executing scripts, displaying outputs, validating the
outputs etc

Ansible playbook has extension as .yml/yaml


Ansible playbooks starts with 3 hypens(-)
---
- Hosts section
- Variable section
- Tasks section
Playbook contains list of play/plays.
Play contains list of hosts, variables and tasks.
Tasks contains list of modules
=============================
eg: sample-playbook.yml
=============================
---
- hosts: all/webservers/webservers,appserver // mention hostgroup/host only when
we have entry in inventory.
become: true
vars:
name: john
port: 8080
hostmachine: 10.0.0.23
tasks:
- name: Copy files from controller to target nodes
copy: src=/https/www.scribd.com/home/ansible/machine-controller.txt dest=//home/ansible/machine-
controller.txt
- name: Install git package
yum: name=git state=present
become: true
- name: Display values
debug:
msg={{ name,port,hostmachine }}
- hosts: appservers
become: true
tasks:
- name: Install httpd server
yum: name=httpd state=present
become: true
- name: Install wget package
yum: name=wget state=present
become: true

====================================
Execution of playbook:
====================================
syntax: ansible-playbook -i /path-to-inventory playbook.yml -vv(verbose)

command: ansible-playbook -i inventory sample-playbook.yml -vv


===================================================================================
===========================
Variables: Variable is temporary storage location for storing the value.
we can declare the variable and assign a value to it.

eg: a=10
echo $a
10

MAVEN_HOME=/opt/maven
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk

==================================
vi variables-playbook.yml
==================================
---
- hosts: webservers
vars:
port: 9000
tasks:
- name: Display Port value
debug:
msg={{ port }}

---
- hosts: webservers
vars:
port:
- 9000
- 9001
- 9002
- 9003
tasks:
- name: Display Port value
debug:
msg={{ port[0],port[1],port[2] }}

---
- hosts: webservers
vars:
port: 8080
server: db-server
tasks:
- name: Display Port value
debug:
msg={{ port, server }}

===================================================================================
============================
Tags: Tag is used for uniquely identifying an task or play.
With help of tags, we can run specific play or task without modifying the
playbook.

=================================================================
Tags at task level:
=================================================================
vi without-tags-at-task-level.yml
============================================
---
- hosts: webservers
become: true
tasks:
- name: Install httpd server
yum: name=httpd state=present
- name: Install wget package
yum: name=wget state=present
- name: Install zip server
yum: name=httpd state=present
- name: Install nginx package
yum: name=nginx state=present

Execution : ansible-playbook -i inventory without-tags-at-task-level.yml -vv

============================================
vi with-tags-at-task-level.yml
============================================
---
- hosts: webservers
become: true
tasks:
- name: Install httpd server
yum: name=httpd state=present
tags:
- install_httpd
- name: Install wget package
yum: name=wget state=present
tags:
- install_wget
- name: Absent zip server
yum: name=zip state=absent
tags:
- install_zip
- name: Install nginx package
yum: name=nginx state=present
tags:
- install_nginx

Execution : ansible-playbook -i inventory with-tags-at-task-level.yml --


tags=install_zip,install_wget -vv
===================================================================================
=====================================
Tags at Play level:
===================================================================================
===================================
vi without-tags-at-play-level.yml
============================================
---
- hosts: webservers
become: true
tasks:
- name: Install httpd server
yum: name=httpd state=present
tags:
- install_httpd
- name: Install wget package
yum: name=wget state=present
tags:
- install_httpd
- name: Install zip server
yum: name=zip state=present
tags:
- install_httpd
- name: Install nginx package
yum: name=nginx state=present
tags:
- install_httpd
- hosts: webservers
become: true
tasks:
- name: Uninstall httpd server
yum: name=httpd state=absent
tags:
- uninstall_httpd
- name: Uninstall wget package
yum: name=wget state=absent
tags:
- uninstall_httpd
- name: Uninstall zip server
yum: name=zip state=absent
tags:
- uninstall_httpd
- name: Uninstall nginx package
yum: name=nginx state=absent
tags:
- uninstall_httpd

Execution : ansible-playbook -i inventory without-tags-at-play-level.yml -vv


===================================================================================
============================
vi with-tags-at-play-level.yml
============================================
---
- hosts: webservers
become: true
tags:
- install_package
tasks:
- name: Install httpd server
yum: name=httpd state=present
tags:
- install_httpd
- name: Install wget package
yum: name=wget state=present
tags:
- install_httpd
- name: Install zip server
yum: name=zip state=present
tags:
- install_httpd
- name: Install nginx package
yum: name=nginx state=present
tags:
- install_httpd
- hosts: webservers
become: true
tags:
- uninstall_package
tasks:

- uninstall_httpd
- name: Uninstall wget package
yum: name=wget state=absent
tags:
- uninstall_httpd
- name: Uninstall zip server
yum: name=zip state=absent
tags:
- uninstall_httpd
- name: Uninstall nginx package
yum: name=nginx state=absent
tags:
- uninstall_httpd

Execution : ansible-playbook -i inventory with-tags-at-play-level.yml --


tags=install_package -vv
===================================================================================
===============================
Register: Register is used catpure the output of task and further we can filter
output for validation

eg: vi register.yml

---
- hosts: webservers
become: true
tasks:
- name: Install httpd server
yum: name=httpd state=present
register: httpd_output
- debug:
var: httpd_output
===================================================================================
==========================================
Handlers:
===================================================================================
==========================================Handlers are used for to avoid
unnecessary restarts for any running service.
Whenever there is any configuration changes in files, automatically handlers will
triggered the restart for services. In case, no configuration is found, it will not
restart the service.

====================================
How handlers works?
====================================
Handlers works with notify keyword/module. Notify keyword/module will inform/call
handlers whenever there is an configuration change and handlers will restart the
service. In case, no change found notify will not call the handlers.
Notify is mentioned under the configuration task.

eg:
===================================
vi without-handlers.yml
===================================
---
- hosts: webservers
become: true
tasks:
- name: Install httpd server
yum: name=httpd state=present
- name: Start the httpd service
service: name=httpd state=started
- name: Configuration file changes
copy: src=/https/www.scribd.com/home/ansible/index.html dest=/var/www/html/index.html
- name: Restart Httpd Service
service: name=httpd state=restarted

=====================================
vi with-handlers.yml
===================================
---
- hosts: webservers
become: true
tasks:
- name: Install httpd server
yum: name=httpd state=present
- name: Start the httpd service
service: name=httpd state=started
- name: Configuration file changes
copy: src=/https/www.scribd.com/home/ansible/index.html dest=/var/www/html/index.html
notify:
- Restart Httpd Service
handlers:
- name: Restart Httpd Service
service: name=httpd state=restarted

===================================================================================
====================================
Loops : Loops are used for performing repetative task.
===================================================================================
===================================
1. Single value loop :

syntax:
with_items: // defining the values
- 'git'
- 'zip'
- 'wget'
- 'httpd'

Call the value: {{ item }}

eg: Installing all the packages


========================================
vi without-single-loop.yml
========================================
---
- hosts: webservers
become: true
tasks:
- name: Install git server
yum: name=git state=present
- name: Install zip server
yum: name=zip state=present
- name: Install wget server
yum: name=wget state=present
- name: Install httpd server
yum: name=httpd state=present

========================================
vi with-single-loop.yml
========================================
---
- hosts: webservers
become: true
tasks:
- name: Install Packages
yum: name={{ item }} state=present
with_items:
- 'git'
- 'zip'
- 'wget'
- 'httpd'
=================================================
2. Multi value loop:

syntax:
with_items: // defining the values
- { name: git, state: present }
- { name: zip, state: absent }
- { name: wget, state: absent }
- { name: httpd, state: latest }

Call the value: {{ item.name }} {{ item.state }}

========================================
vi without-multi-loop.yml
========================================
---
- hosts: webservers
become: true
tasks:
- name: Install git server
yum: name=git state=present
- name: Uninstall zip server
yum: name=zip state=absent
- name: Uninstall wget server
yum: name=wget state=absent
- name: Upgrade httpd server
yum: name=httpd state=latest

========================================
vi with-multi-loop.yml
========================================
---
- hosts: webservers
become: true
tasks:
- name: Package Management
yum: name={{ item.name }} state={{ item.state }}
with_items:
- { name: git, state: present }
- { name: zip, state: absent }
- { name: wget, state: absent }
- { name: httpd, state: latest }
===================================================================================
=========================
Templates:
===================================================================================
========================
Template is a file which contains actual values of configuration file which helps
to replace the default values of configuration files while
installation/Upgradation.
Templates called as jinja templates.
Templates have an extension as .j2

eg: Perform tomcat configuration 10 machines.


PORT - 8090
=======================================================
vi server.xml.j2
=======================================================
<Connector port="{{ PORT }}" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
=========================================================
vi tomcat-configuration.yml
=========================================================
---
- hosts: webservers
become: true
vars:
PORT: 8090
tasks:
- name: Tomcat server.xml changes
template: src=/https/www.scribd.com/home/ansible/server.xml.j2 dest=/app/server.xml
============================================================
output: cat /app/server.xml
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
==================================================================
Instead of variable - we can use group_vars/all
mkdir group_vars
cd group_vars
vi all
PORT: 8090
===================================================================
Roles:
===================================================================
Roles contains list of playbook.
Roles are used for dividing the complex playbook into small playbooks so that we
can easily identify and debug the issues.
Roles provides flexibility in terms of debugging and fixing errors as playbook will
fail in particular yaml file.
With roles , we can re-use the playbook for different activitites.

Default Roles: /etc/ansible/roles


Custom role: ansible-galaxy init role_name

Module - ansible
Playbook - ansible-playbook
Roles - ansible-galaxy

Directory structure of Roles:

[ansible@ip-172-31-2-51 httpd_role]$ tree


.
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml

8 directories, 8 files
[ansible@ip-172-31-2-51 httpd_role]$
===================================================================================
=======================================
eg: Divide playbook into small playbooks via roles:
===================================================================================
=======================================
---
- hosts: webservers
become: true
tasks:
- name: Install httpd server
yum: name=httpd state=present
- name: Start the httpd service
service: name=httpd state=started
- name: Configuration file changes
copy: src=/https/www.scribd.com/home/ansible/index.html dest=/var/www/html/index.html
notify:
- Restart Httpd Service
handlers:
- name: Restart Httpd Service
service: name=httpd state=restarted
===================================================================================
===================================
1. Create an custom role :
[ansible@ip-172-31-2-51 ~]$ ansible-galaxy init httpd_role
- Role httpd_role was created successfully
[ansible@ip-172-31-2-51 ~]$
===================================================================================
===================================
2. cd httpd_role/tasks
===================================================================================
===================================
a. install.yml
b. service.yml
c. configure.yml
d. main.yml
===================================================================================
====================================
a. vi install.yml
---
- name: Install httpd server
yum: name=httpd state=present

b. vi service.yml
---
- name: Start the httpd service
service: name=httpd state=started

c. vi configure.yml
---
- name: Configuration file changes
copy: src=index.html dest=/var/www/html/index.html
notify:
- Restart Httpd Service
d. vi main.yml
---
- import_tasks: install.yml
- import_tasks: service.yml
- import_tasks: configure.yml
===================================================================================
=====================================
3. cd httpd_role/files
vi index.html
<H1> Static website via roles </H1>
===================================================================================
====================================
4. cd httpd_role/handlers
vi main.yml
---
- name: Restart Httpd Service
service: name=httpd state=restarted
===================================================================================
======================================
5. cd httpd_role/meta
vi main.yml
Gallaxy_info:
name:
description:
===================================================================================
======================================
Main playbook should be outside the roles directory.
vi setup_httpd_role.yml
---
- hosts: webservers
become: true
roles:
- httpd_role
===================================================================================
=====================================
Execution: ansible-playbook -i inventory setup_httpd_role.yml -vv
===================================================================================
=====================================
Tips and Tricks of Ansible:
===================================================================================
=====================================
1. limit : Limit is a filter where we can run playbooks on specific hosts/IP's
without editing the inventory file.

command: ansible-playbook -i inventory sample.yml --limit=host/IP1,IP2,IP3... -vv

eg : 100 machines in inventory, On 96 machines are successfully playbook was


executed, 4 machines playbook didnt execute due to network issues.
Now we want to run playbook on failed 4 machines only?

===================================================================================
======================================
2. skip-tags: skip-tags is used for skipping the particular task from playbooks.

command: ansible-playbook -i inventory with-tags-at-task-level.yml --skip-


tags=install_nginx,install_wget -vv

===================================================================================
======================================
3. start-at-task: start-at-task is used for start running playbook from particular
task.

eg: 20 tasks in a playbook, start playbook execution from 12th task till the end.

command: ansible-playbook -i inventory sample.yml --start-at-task="Display values"


-vv

===================================================================================
======================================
4. step: step is used for step by step execution and debugging the playbooks.
step will pause after every task and take confirmation and then proceed.

command: ansible-playbook -i inventory sample.yml --step -vv

(y) - run the task


(n) - do not run task
(c) - continue to run rest of the task in playbook.

Perform task: TASK: Gathering Facts (N)o/(y)es/(c)ontinue: y

===================================================================================
=========================================
5. list-hosts: list-hosts will be list all the hosts/IP inside in the inventory on
which playbooks the hosts/IP are going to be executed.

command: ansible-playbook -i inventory sample.yml --list-hosts -vv

[ansible@ip-172-31-2-51 ~]$ ansible-playbook -i inventory sample.yml --list-hosts

playbook: sample.yml

play #1 (webservers): webservers TAGS: []


pattern: ['webservers']
hosts (2):
172.31.2.51
172.31.9.124
[ansible@ip-172-31-2-51 ~]$

===================================================================================
==========================================
6.syntax-check :syntax check verifies whether all the script written inside the
playbook is according to ansible standardsie its verifying the ansible syntax.

command: ansible-playbook -i inventory sample.yml --syntax -vv


ansible-playbook -i inventory sample.yml --syntax-check -vv

[ansible@ip-172-31-2-51 ~]$ ansible-playbook -i inventory sample.yml --syntax

ERROR! We were unable to read either as JSON nor YAML, these are the errors we got
from each:
JSON: Expecting value: line 1 column 1 (char 0)

Syntax Error while loading YAML.


could not find expected ':'

The error appears to be in '/home/ansible/sample.yml': line 5, column 8, but may


be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

vars
name: john
^ here
[ansible@ip-172-31-2-51 ~]$ vi sample.yml
[ansible@ip-172-31-2-51 ~]$ ansible-playbook -i inventory sample.yml --syntax

playbook: sample.yml
[ansible@ip-172-31-2-51 ~]$
===================================================================================
=====================================
7.ping: Ping is used checking the connnectivity between the controller machine and
target nodes.

command: ansible all -i inventory -m ping


ansible webservers -i inventory -m ping

[ansible@ip-172-31-2-51 ~]$ ansible all -i inventory -m ping


172.31.9.124 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
172.31.2.51 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
127.0.0.1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
10.0.0.3 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host 10.0.0.3
port 22: Connection timed out",
"unreachable": true
}
[ansible@ip-172-31-2-51 ~]$ ansible webservers -i inventory -m ping
172.31.9.124 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
172.31.2.51 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
[ansible@ip-172-31-2-51 ~]$

===================================================================================
=================================

You might also like