説明
演習問題
Q1. プレイブック「 install_package.yml 」は Webmin と Apache を一度にインストールします。これをタグを使用して Webmin だけ、Apache だけをインストールするよう変更してください。
- インベントリーファイルの内容hosts.yml
--- all: hosts: marutamachi:
group_vars/all.yml--- ansible_user: vagrant ansible_password: vagrant
host_vas/marutamachi.yml--- ansible_host: 192.168.111.101
- 変更対象のプレイブックinstall_package.yml
--- - name: Install multiple packages. hosts: all gather_facts: no become: yes tasks: - name: Register a repository for Webmin. ansible.builtin.blockinfile: path: "/etc/yum.repos.d/webmin.repo" create: yes block: | [webmin] name=Webmin Repository baseurl=http://download.webmin.com/download/yum/ gpgcheck=1 enabled=1 gpgkey=http://www.webmin.com/jcameron-key.asc state: present - name: Install the perl-Net-SSLeay module. ansible.builtin.dnf: name: perl-Net-SSLeay state: present - name: Install the Webmin module. ansible.builtin.dnf: name: webmin state: present - name: Install the httpd module. ansible.builtin.dnf: name: httpd state: present - name: Start httpd service. ansible.builtin.systemd: name: httpd.service state: started
解答
- ディレクトリー「 host_vars/ 」と「 group_vars/ 」の内容 / 構成は変更しません(そのまま使用します)。
instal_package.yml
---
- name: Install multiple packages.
hosts: all
gather_facts: no
become: yes
tasks:
- name: Register a repository for Webmin.
ansible.builtin.blockinfile:
path: "/etc/yum.repos.d/webmin.repo"
create: yes
block: |
[webmin]
name=Webmin Repository
baseurl=http://download.webmin.com/download/yum/
gpgcheck=1
enabled=1
gpgkey=http://www.webmin.com/jcameron-key.asc
state: present
tags: webmin
- name: Install the perl-Net-SSLeay module.
ansible.builtin.dnf:
name: perl-Net-SSLeay
state: present
tags: webmin
- name: Install the Webmin module.
ansible.builtin.dnf:
name: webmin
state: present
tags: webmin
- name: Install the httpd module.
ansible.builtin.dnf:
name: httpd
state: present
tags: apache
- name: Start httpd service.
ansible.builtin.systemd:
name: httpd.service
state: started
tags: apache
タグ webmin を指定した実行ログ
y_mrok@ctrl:~/code/chap26$ ansible-playbook -i hosts.yml -t webmin install_package.yml
PLAY [Install multiple packages.] ********************************************************************************************************************
TASK [Register a repository for Webmin.] *************************************************************************************************************
changed: [marutamachi]
TASK [Install the perl-Net-SSLeay module.] ***********************************************************************************************************
changed: [marutamachi]
TASK [Install the Webmin module.] ********************************************************************************************************************
changed: [marutamachi]
PLAY RECAP *******************************************************************************************************************************************
marutamachi : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
y_mrok@ctrl:~/code/chap26$
タグ apache を指定した実行ログ
y_mrok@ctrl:~/code/chap26$ ansible-playbook -i hosts.yml -t apache install_package.yml
PLAY [Install multiple packages.] ********************************************************************************************************************
TASK [Install the httpd module.] *********************************************************************************************************************
changed: [marutamachi]
TASK [Start httpd service.] **************************************************************************************************************************
changed: [marutamachi]
PLAY RECAP *******************************************************************************************************************************************
marutamachi : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
y_mrok@ctrl:~/code/chap26$
冪等性を確認
y_mrok@ctrl:~/code/chap26$ ansible-playbook -i hosts.yml -t webmin install_package.yml
PLAY [Install multiple packages.] ********************************************************************************************************************
TASK [Register a repository for Webmin.] *************************************************************************************************************
ok: [marutamachi]
TASK [Install the perl-Net-SSLeay module.] ***********************************************************************************************************
ok: [marutamachi]
TASK [Install the Webmin module.] ********************************************************************************************************************
ok: [marutamachi]
PLAY RECAP *******************************************************************************************************************************************
marutamachi : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
y_mrok@ctrl:~/code/chap26$
y_mrok@ctrl:~/code/chap26$ ansible-playbook -i hosts.yml -t apache install_package.yml
PLAY [Install multiple packages.] ********************************************************************************************************************
TASK [Install the httpd module.] *********************************************************************************************************************
ok: [marutamachi]
TASK [Start httpd service.] **************************************************************************************************************************
ok: [marutamachi]
PLAY RECAP *******************************************************************************************************************************************
marutamachi : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
y_mrok@ctrl:~/code/chap26$
Q2. 管理対象ノード上で webmin と Apache が動作していることを確認してください。
解答
- Webmin
https://192.168.111.101:10000/
- Apache
http://192.168.111.101/