Ansible Learning Notes 2

1. A new host was created, and a snapshot was taken for easy rollback. Passwordless login was set up in the same way, and then added to the hosts list. A copy test was conducted to prepare for the following playbooks.

Ansible Learning Notes 2

Ansible Learning Notes 2

2. The Ansible control machine installs nginx and downloads the Linux 7 ISO as the image source for the controlled end.

2.1 First, create an ISO folder linked to the nginx directory. Here, a directory named rhel7 was created in the nginx root directory to distinguish it from the main directory.

Ansible Learning Notes 2

2.2 Accessing the rhel7 directory on the controlled end should show the contents of the files copied earlier. Wait for the ISO file to finish downloading before mounting it.

Ansible Learning Notes 2

2.3 Create a vm1.html file in the ISO directory, which should also be accessible.

Ansible Learning Notes 2

2.4 Mount the ISO and create a local dvd.repo, then push it to each controlled node to create the file.

Ansible Learning Notes 2

Use copy to push.

Ansible Learning Notes 2

Check on the target host.

Ansible Learning Notes 2

3. Playbooks are configured according to the following scenarios (official website): web (vm2, vm3), db (vm3), log (vm3).

Ansible Learning Notes 2

3.1 Error handling. An error occurred during this process. Because the RPM key was not in the directory pointed to by dvd.repo, it needed to be downloaded and copied in.

The error is as follows:

Ansible Learning Notes 2

Download the key.

Ansible Learning Notes 2

Rename and copy to the controlled node.

Ansible Learning Notes 2

The playbooks executed successfully, but there was still a small issue. Since my vm2 machine had previously installed nginx, there was a port conflict. After killing nginx and re-executing, it installed normally.

Ansible Learning Notes 2

Ansible Learning Notes 2

Note: After this configuration, there was a problem (in my environment). I used the rsyslog host as both web and db server, which caused it to write logs to itself, resulting in a log loop. The disk filled up quickly.

Ansible Learning Notes 2

I can only clear the address recorded in the /etc/rsyslog.conf of the logging machine vm3, so that another machine can log here. The main focus is still on studying Ansible, not getting bogged down in this.

Leave a Comment