Ansible | APT module を試してみた

Ansible の APT モジュールでパッケージのインストールを試してみた。

パッケージをインストールする

設定

playbook.yml

1
2
3
4
5
6
- hosts: test-hosts
tasks:
- name: Install the package "curl"
become: true
apt:
name: curl

実行

1
2
3
4
5
6
7
8
9
10
11
12
13
$ ansible-playbook -i hosts playbook.yml -K
SUDO password:

PLAY [test-hosts] **************************************************************

TASK [setup] *******************************************************************
ok: [192.168.1.201]

TASK [Install the package "curl"] **********************************************
changed: [192.168.1.201]

PLAY RECAP *********************************************************************
192.168.1.201 : ok=2 changed=1 unreachable=0 failed=0

パッケージをアンインストールする (remove)

パッケージを削除するが、設定ファイルは残る。

設定

playbook.yml

1
2
3
4
5
6
7
- hosts: test-hosts
tasks:
- name: Remove the package "curl"
become: true
apt:
name: curl
state: absent

実行

1
2
3
4
5
6
7
8
9
10
11
12
13
$ ansible-playbook -i hosts playbook.yml -K
SUDO password:

PLAY [test-hosts] **************************************************************

TASK [setup] *******************************************************************
ok: [192.168.1.201]

TASK [Remove the package "curl"] ***********************************************
changed: [192.168.1.201]

PLAY RECAP *********************************************************************
192.168.1.201 : ok=2 changed=1 unreachable=0 failed=0

パッケージをアンインストールする (purge)

パッケージを設定ファイルごと削除する

設定

playbook.yml

1
2
3
4
5
6
7
8
- hosts: test-hosts
tasks:
- name: Purge the package "curl"
become: true
apt:
name: curl
state: absent
purge: yes

実行

1
2
3
4
5
6
7
8
9
10
11
12
13
$ ansible-playbook -i hosts playbook.yml -K
SUDO password:

PLAY [test-hosts] **************************************************************

TASK [setup] *******************************************************************
ok: [192.168.1.201]

TASK [Purge the package "curl"] ************************************************
changed: [192.168.1.201]

PLAY RECAP *********************************************************************
192.168.1.201 : ok=2 changed=1 unreachable=0 failed=0

パッケージを更新する

設定

playbook.yml

1
2
3
4
5
6
- hosts: test-hosts
tasks:
- name: apt update
become: true
apt:
update_cache: yes

実行

1
2
3
4
5
6
7
8
9
10
11
12
13
$ ansible-playbook -i hosts playbook.yml -K
SUDO password:

PLAY [test-hosts] **************************************************************

TASK [setup] *******************************************************************
ok: [192.168.1.201]

TASK [apt update] **************************************************************
changed: [192.168.1.201]

PLAY RECAP *********************************************************************
192.168.1.201 : ok=2 changed=1 unreachable=0 failed=0