<style> html, body, .ui-content { background-color: #333; color: #ddd; } .markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { color: #ddd; } .markdown-body h1, .markdown-body h2 { border-bottom-color: #ffffff69; } .markdown-body h1 .octicon-link, .markdown-body h2 .octicon-link, .markdown-body h3 .octicon-link, .markdown-body h4 .octicon-link, .markdown-body h5 .octicon-link, .markdown-body h6 .octicon-link { color: #fff; } .markdown-body img { background-color: transparent; } .ui-toc-dropdown .nav>.active:focus>a, .ui-toc-dropdown .nav>.active:hover>a, .ui-toc-dropdown .nav>.active>a { color: white; border-left: 2px solid white; } .expand-toggle:hover, .expand-toggle:focus, .back-to-top:hover, .back-to-top:focus, .go-to-bottom:hover, .go-to-bottom:focus { color: white; } .ui-toc-dropdown { background-color: #333; } .ui-toc-label.btn { background-color: #191919; color: white; } .ui-toc-dropdown .nav>li>a:focus, .ui-toc-dropdown .nav>li>a:hover { color: white; border-left: 1px solid white; } .markdown-body blockquote { color: #bcbcbc; } .markdown-body table tr { background-color: #5f5f5f; } .markdown-body table tr:nth-child(2n) { background-color: #4f4f4f; } .markdown-body code, .markdown-body tt { color: #eee; background-color: rgba(230, 230, 230, 0.36); } a, .open-files-container li.selected a { color: #5EB7E0; } </style> # Ansible in SUMA 1. 在 Ansible control node 或是 agent 上先安裝 ansible ```sudo zypper install ansible``` ```zypper info ansible``` ![](https://i.imgur.com/W40h11s.png) ```ansible --version``` ![](https://i.imgur.com/hTZ28nj.png) 2. (1) 檢查完成後回到 SUMA 點選 ansible node control * Systems >>> Overview >>> ansiblenode(ansible node control VM) * Detail >>> Properties >>> Add-On System Types >>> Ansible Control Node ![](https://i.imgur.com/zxcmDpp.png) * 勾選完後 >>> Update Properties,完成變更後就可以看到 Ansible 選項在畫面上 ![](https://i.imgur.com/e9GUmTN.png) 3. 分別建立 playbook資料夾 及 inventory file ![](https://i.imgur.com/8gY5GbU.png) * playbook 資料夾必須手動進入 ansible node 建立 4. 執行 playbook * Ansible >>> Playbook >>> Playbookfile ![](https://i.imgur.com/DxPBaVy.png) * 按下 Schedule 就可以馬上執行 playbookfile ![](https://i.imgur.com/cNU71Ff.png) 5. 執行結果 * Events >>> History ![](https://i.imgur.com/UkVnOdB.png) * playbook.yml file ``` - hosts: (hostname or ip-address) tasks: # Task 1 for test connection - name: Test connection ping: register: result - name: Print result debug: msg: "{{ result }}" # Task 2 for Create file test - name: Create files file: path: /tmp/test1.txt state: touch become: yes register: files - name: Check files debug: msg: "{{ files }}" # Task 3 for install apache and start apache server - name: Install apache server zypper: name: apache2 state: present register: apache.info - name: check apache2 debug: msg: "{{ apache.info }}" - name: start apache ansible.builtin.systemd: name: apache2 status: started enabled: yes register: apached - name: check apache2 enabled debug: msg: "{{ apached }}" ``` * 可於 VM 內使用 command 做檢查 ```ansible-playbook -C $(filename).yml```