官术网_书友最值得收藏!

Reviewing and running the playbook

Putting everything together, we now have the following playbook (called common_tasks.yaml for simplicity):

--- 
- hosts: all
remote_user: ansible
tasks:
- name: Ensure EPEL is enabled
yum:
name: epel-release
state: present
become: True
- name: Ensure libselinux-python is present
yum:
name: libselinux-python
state: present
become: True
...

Since this playbook is pretty complex, we can run the following:

$ ansible-playbook common_tasks.yaml --list-tasks  

This asks Ansible to print all the tasks in a shorter form so that we can quickly see what tasks a playbook performs. The output should be something like the following:

playbook: common_tasks.yaml
play #1 (all): all TAGS: []
tasks:
Ensure EPEL is enabled TAGS: []
Ensure libselinux-python is present TAGS: []
Ensure libsemanage-python is present TAGS: []
Ensure we have last version of every package TAGS: []
Ensure NTP is installed TAGS: []
Ensure the timezone is set to UTC TAGS: []
Ensure the NTP service is running and enabled TAGS: []
Ensure FirewallD is installed TAGS: []
Ensure FirewallD is running TAGS: []
Ensure SSH can pass the firewall TAGS: []
Ensure the MOTD file is present and updated TAGS: []
Ensure the hostname is the same of the inventory TAGS: []

We can now run the playbook with the following:

$ ansible-playbook -i test01.fale.io, common_tasks.yaml

We will receive the following output. Full code output is available on GitHub.

PLAY [all] ***************************************************

TASK [Gathering Facts] ***************************************
ok: [test01.fale.io]

TASK [Ensure EPEL is enabled] ********************************
changed: [test01.fale.io]

TASK [Ensure libselinux-python is present] *******************
ok: [test01.fale.io]

TASK [Ensure libsemanage-python is present] ******************
changed: [test01.fale.io]

TASK [Ensure we have last version of every package] **********
changed: [test01.fale.io]
...
主站蜘蛛池模板: 炉霍县| 海伦市| 黔江区| 玉林市| 永寿县| 合水县| 江阴市| 梅州市| 彩票| 永济市| 龙江县| 霞浦县| 亳州市| 西平县| 彭州市| 岳池县| 澜沧| 托克逊县| 南宫市| 宝鸡市| 当雄县| 容城县| 杭锦后旗| 民乐县| 南康市| 裕民县| 德江县| 金寨县| 正宁县| 全南县| 楚雄市| 东兴市| 杭锦后旗| 岚皋县| 齐河县| 西宁市| 临清市| 陵川县| 桑植县| 甘孜县| 峨山|