antony@notes:~/suse$ cat "Setup-Ansible-on-SUSE-Manager.md"
Setup Ansible on SUSE Manager
Setup Ansible on SUSE Manager
安裝 Ansible 套件
選擇一台 SUSE Manger 的 Client 端當作 Ansible control node
在該台 Node,執行以下命令
$ sudo zypper install ansible檢查是否成功安裝
$ zypper info ansible | grep -w "Installed"螢幕輸出
Installed Size : 96.1 MiB
Installed : YesAdd Ansible Control Node
在 SUMA Web UI 上點選
- Systems »> Overview »> SLES-15-SP4-Client-2 (Ansible control node VM)
- Detail »> Properties »> Add-On System Types »> Ansible Control Node

勾選完後 »> “Update Properties”,完成變更後就可以看到 Ansible 選項在畫面上
建立 Playbook 目錄 及 Inventory files
在 Ansible Control Node 執行以下命令
$ mkdir -p /srv/ansible/playbooks
在 “Add a Playbook directory” 欄位中,輸入 “/srv/ansible/playbooks” ,按 “Save” 儲存

在 “Add a Playbook directoryInventory file” 欄位中,輸入 “/etc/ansible/hosts” ,按 “Save” 儲存
執行 Playbook
在 Ansible Control Node 執行以下命令
編輯 Playbook 任務的設定檔
$ vim apache2.yml檔案內容 :
- hosts: localhost
tasks:
# Task 1 for test connection
- name: Test connection
ping:
register: result
# Task 2 for Create file test
- name: Create files
file:
path: /tmp/test1.txt
state: touch
become: yes
register: files
# Task 3 for install apache and start apache server
- name: Install apache server
zypper:
name: apache2
state: present
- name: start apache
ansible.builtin.systemd:
name: apache2
state: started
enabled: yes在 Ansible Control Node 本機執行以下任務
- 任務一 : 測試 Connection
- 任務二 : 建立
/tmp/test1.txt檔案- 任務三 : 安裝 apache2 Server
- 任務四 : 啟動 apache2 服務 並設為開機自動執行
回到 SUSE Manager Web UI

點選 “Ansible” »> “Playbooks” »> 展開 “/srv/ansible/playbooks” »> 點選 “apache2.yml”

點選 “Schedule” ,立刻安排 Playbook 任務

點選 “Events” ,查看執行結果
回到 Command Line 執行以下檢查命令
$ systemctl status apache2.service螢幕輸出
● apache2.service - The Apache Webserver
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2023-05-08 15:35:26 CST; 22min ago
Main PID: 23829 (httpd-prefork)
Status: "Processing requests..."
Tasks: 6
CGroup: /system.slice/apache2.service
├─23829 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/syscon>
├─23836 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/syscon>
├─23837 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/syscon>
├─23838 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/syscon>
├─23839 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/syscon>
└─23840 /usr/sbin/httpd-prefork -DSYSCONFIG -C "PidFile /run/httpd.pid" -C "Include /etc/apache2/syscon>
May 08 15:35:26 SLES-15-SP4-Client-2 systemd[1]: Starting The Apache Webserver...
May 08 15:35:26 SLES-15-SP4-Client-2 start_apache2[23829]: AH00558: httpd-prefork: Could not reliably determine the >
May 08 15:35:26 SLES-15-SP4-Client-2 systemd[1]: Started The Apache Webserver.