Free Learning of RHCE: Deploying Ansible

Free Learning of RHCE: Deploying Ansible

Introduction to Ansible

RECRUIT

1. What is Ansible?

Ansible is a newly emerging automation operation and maintenance tool developed based on Python, which integrates the advantages of many operation and maintenance tools (puppet, chef, func, fabric) to achieve functions such as batch system configuration, batch program deployment, and batch command execution.

Ansible is developed based on paramiko and works on a modular basis; it does not have the capability for batch deployment by itself. The real batch deployment capability comes from the modules that Ansible runs; Ansible merely provides a framework. Ansible does not require the installation of clients/agents on remote hosts because it communicates with remote hosts via SSH. Ansible has now been officially acquired by Red Hat.

2. Ansible Management Method

Ansible is a model-driven configuration manager that supports multi-node deployment and remote task execution. It uses SSH for remote connections by default. There is no need to install additional software on the managed nodes, and it can be extended using various programming languages. The Ansible management system consists of a control host and a group of managed nodes. The control host directly controls the managed nodes via SSH, and the managed nodes are grouped and managed through Ansible’s inventory.

3. Ansible Architecture

Free Learning of RHCE: Deploying Ansible

4. Ansible Task Execution Modes

The operations of the control host on the managed nodes can be divided into two categories: ad-hoc and playbook:

(1) Ad-hoc mode (point-to-point mode)

Using a single module, it supports batch execution of a single command. An ad-hoc command is a command that can be quickly entered and does not need to be saved. It is equivalent to a one-liner shell command in bash.

(2) Playbook mode (script mode)

This is the main management method of Ansible and the key to Ansible’s powerful functionality. Playbooks complete a type of function through multiple task collections, such as the installation and deployment of web services, or batch backups of database servers. A playbook can be simply understood as a configuration file that combines multiple ad-hoc operations.

5. Ansible Execution Process

Free Learning of RHCE: Deploying Ansible

Ansible Deployment

RECRUIT

1. Install RHEL9 Version Virtual Machine

Configure IP information

2. Configure Local Yum Repository, Create server.repo in /etc/yum.repos.d/ Directory, Then Configure.

mount /dev/cdrom /mnt

vim /etc/yum.repos.d/server.repo

[aa]

name=aa1

baseurl=file:///mnt/BaseOS

enabled=1

gpgcheck=0

[bb]

name=bb1

baseurl=file:///mnt/AppStream

enabled=1

gpgcheck=0

Save and Exit

3. Install Software Package Groups

yum group install “Virtualization Client” “Virtualization Hypervisor” “Virtualization Tools” -y

4. Restart libvirtd Service and Set to Start on Boot

Systemctl restart libvirtd

Systemctl enable libvirtd

5. Upload Local RHEL9.2 Image to Virtual Machine

6. Use virt-manager to Open Virtual Console for System Installation

7. Clone 5 Nodes + One Just Installed, Total 6 Hosts

192.168.122.100 master.example.com

192.168.122.10 node1.example.com

192.168.122.20 node2.example.com

192.168.122.30 node3.example.com

192.168.122.40 node4.example.com

192.168.122.50 node5.example.com

8. For All Hosts, When Configuring IP, Pay Attention to Remove the UUID from the Network Configuration File

9. For All Hosts, Edit /etc/hosts

192.168.122.1 ansible.example.com ansible

192.168.122.100 master.example.com master

192.168.122.10 node1.example.com node1

192.168.122.20 node2.example.com node2

192.168.122.30 node3.example.com node3

192.168.122.40 node4.example.com node4

192.168.122.50 node5.example.com node5

10. Configure Passwordless Login for Master Host

(1) Operate with root user and student user separately

ssh-keygen Press Enter until Finished

(root user)

for i in node{1..5}

do ssh-copy-id -i ~/.ssh/id_rsa.pub root@$i

done

for i in node{1..5}

do ssh-copy-id -i ~/.ssh/id_rsa.pub student@$i

done

(student user)

for i in node{1..5}

do ssh-copy-id -i ~/.ssh/id_rsa.pub root@$i

done

for i in node{1..5}

do ssh-copy-id -i ~/.ssh/id_rsa.pub student@$i

done

11. Configure Yum Repository

Configure local yum repository on the host machine ansible, then install

httpd service

Upload package files to /var/www/html/ directory, then

Restart httpd service and set to start on boot

Turn off firewall, selinux

12. Deploy Yum Repository on Master Host

vi /etc/yum.repos.d/server.repo

[aa]

name=aa1

baseurl=http://ansible.example.com/rhel9/BaseOS

enabled=1

gpgcheck=0

[cc]

name=cc1

baseurl=http://ansible.example.com/rhel9/AppStream

enabled=1

gpgcheck=0

[dd]

name=dd1

baseurl=http://ansible.example.com/ansible-automation-platform

enabled=1

gpgcheck=0

13. Grant Privileges to Student User

vim /etc/sudoers.d/student

student ALL=(ALL) NOPASSWD: ALL

14. Install Ansible

Switch to student user su – student

sudo yum -y install ansible-core ansible-navigator

Free Learning of RHCE: Deploying Ansible

Leave a Comment