Bài tập Ansible playbook trong khóa học Linux chuyên sâu cho Dev DevOps

Ansible playbook là 1 thành phần cơ bản không thể thiếu được của Ansible automation platform.

Ansible playbook được tạo từ các task đơn vị nhỏ nhất của Ansible

Ansible task gọi tới ansible module để làm 1 công việc nào đó, khai báo ở dạng key value

Khóa học Linux chuyên sâu cho Dev DevOps có bài tập Ansible như này

Hình Ansible Hands-on Labs

Viết Ansible playbook coi kết quả lịnh

systemctl status apache2 –no-pager trên Ubuntu Server 22.04

systemctl status httpd –no-pager trên AlmaLinux 9

Chạy playbook cho kết quả như thía này

root@ubuntuserver2204:~# ansible-playbook 2webservers-check.yml –flush-cache

PLAY [webservers] *

TASK [Gathering Facts] **

[WARNING]: Platform linux on host 192.168.198.12 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.12/reference_appendices/interpreter_discovery.html for more information.

ok: [192.168.198.12]

ok: [192.168.198.146]

TASK [Đăng kí dịch vụ httpd] **

skipping: [192.168.198.146]

changed: [192.168.198.12]

TASK [Coi dịch vụ httpd]

ok: [192.168.198.12] =>

msg: |-

● httpd.service – The Apache HTTP Server

Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)

Active: active (running) since Thu 2023-04-20 19:37:07 +07; 9s ago

Docs: man:httpd.service(8)

Main PID: 1397 (httpd)

Status: “Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec: 0 B/sec”

Tasks: 213 (limit: 2517)

Memory: 19.9M

CPU: 78ms

CGroup: /system.slice/httpd.service

├─1397 /usr/sbin/httpd -DFOREGROUND

├─1398 /usr/sbin/httpd -DFOREGROUND

├─1399 /usr/sbin/httpd -DFOREGROUND

├─1400 /usr/sbin/httpd -DFOREGROUND

└─1401 /usr/sbin/httpd -DFOREGROUND

Apr 20 19:37:07 alma9 systemd[1]: Starting The Apache HTTP Server…

Apr 20 19:37:07 alma9 httpd[1397]: AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using fe80::20c:29ff:fe5b:e9a8%ens160. Set the ‘ServerName’ directive globally to suppress this message

Apr 20 19:37:07 alma9 systemd[1]: Started The Apache HTTP Server.

Apr 20 19:37:07 alma9 httpd[1397]: Server configured, listening on: port 80

skipping: [192.168.198.146]

TASK [Đăng kí dịch vụ apache2]

skipping: [192.168.198.12]

changed: [192.168.198.146]

TASK [Coi dịch vụ apache2]

skipping: [192.168.198.12]

ok: [192.168.198.146] =>

msg: |-

● apache2.service – The Apache HTTP Server

Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)

Active: active (running) since Thu 2023-04-20 12:35:41 UTC; 1min 36s ago

Docs: https://httpd.apache.org/docs/2.4/

Process: 844 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)

Main PID: 911 (apache2)

Tasks: 55 (limit: 2193)

Memory: 7.5M

CPU: 90ms

CGroup: /system.slice/apache2.service

├─911 /usr/sbin/apache2 -k start

├─917 /usr/sbin/apache2 -k start

└─918 /usr/sbin/apache2 -k start

Apr 20 12:35:40 ubuntuserver2204 systemd[1]: Starting The Apache HTTP Server…

Apr 20 12:35:40 ubuntuserver2204 apachectl[875]: AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message

Apr 20 12:35:41 ubuntuserver2204 systemd[1]: Started The Apache HTTP Server.

PLAY RECAP

192.168.198.12 : ok=3 changed=1 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0

192.168.198.146 : ok=3 changed=1 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0