Setup Remote Host in Ansible - RHCE .pdf

support8872 488 views 12 slides Oct 08, 2024
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

Slides on how to setup remote host in ansible - Part of RHCE syllabus


Slide Content

Setup remote host in Ansible

Inventory File

●Default inventory file used by ansible -
/etc/ansible/hosts
○Defines the hosts or groups of
hosts
○Contains the list of IP addresses or
domain names of the remote hosts
○Can be either dynamic or static
Remote hosts

Listing remote hosts in Inventory

app1.example.com
app2.example.com
web1.example.com
207.198.210.35
203.168.20.13



●Each host is listed on a separate line

●Allows ansible to know exactly which
hosts to connect to

Aliases refer to the names (server1, server2, etc.) used to represent each host, allowing
for easier reference instead of using the full IP address

●List host files
Command: ansible-inventory --list
Note: As we have not added any hosts so far that’s why it is empty
Setup remote host connection

●Add the host
Command: echo 'ip_address' > /etc/ansible/hosts
●Verify the added host
Command: cat /etc/ansible/hosts

●List the host file after the hosts has been added
Command: ansible-inventory --list


Added host

●Generate the SSH keys on control node to connect remote hosts without
password
Command: ssh-keygen

●Copy the SSH keys to the remote host
Command: ssh-copy-id <ip_address>
Note: Enter the password when prompted

●Ping all the hosts in the inventory file using ansible ad-hoc command
Command: ansible all -m ping
Pong means the remote host is reachable

Check the uptime of all the hosts in the inventory file
●Command: ansible –a “uptime” all