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

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]
...
主站蜘蛛池模板: 太白县| 文昌市| 中江县| 榆中县| 西昌市| 旬邑县| 招远市| 东乌| 罗山县| 北辰区| 色达县| 鄱阳县| 潼关县| 浮山县| 武宁县| 科尔| 库车县| 玉田县| 邓州市| 岚皋县| 远安县| 兰坪| 桓台县| 稻城县| 壤塘县| 南漳县| 巨野县| 昭觉县| 达州市| 巴青县| 顺义区| 乳山市| 绥芬河市| 全南县| 梁山县| 闽清县| 金溪县| 桦川县| 中阳县| 行唐县| 科尔|