在安裝 docker 之前,有一些套件是必需要用到,使用 ansible 統一部署安裝:目前個人覺得可程式化部署最方便
增加以下變數清單:
其實一般照原則是要統一放在 vars.yml,為了能讓大家更了解直接寫在全域變數較容易理解
vars:
requried_packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
主程式說明:
部署程式跟之前的差別如下:
1.增加 list vars
2.利用項目迴圈安裝
- hosts: web7
name: play-test
gather_facts: no
become: yes
vars:
ansible_become: yes
ansible_become_method: sudo
ansible_become_pass: docker
requried_packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
tasks:
- name: Install required packages
apt:
name: "{{ item }}"
state: latest
update_cache: true
loop: "{{ requried_packages }}"
執行以下程式:
ansible-playbook -i inventory.ini playbook6.yml
成功畫面如下:
joulong@joulong1:~/playbook/docker$ ansible-playbook -i inventory.ini playbook6.yml
PLAY [play-test] *********************************************************************************************************************************************************************************************
TASK [Install required packages] *****************************************************************************************************************************************************************************
changed: [server1] => (item=apt-transport-https)
changed: [server1] => (item=ca-certificates)
changed: [server1] => (item=curl)
changed: [server1] => (item=gnupg-agent)
changed: [server1] => (item=software-properties-common)
PLAY RECAP ***************************************************************************************************************************************************************************************************
server1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0