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

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]
...
主站蜘蛛池模板: 仙游县| 吉安市| 丹巴县| 海阳市| 安塞县| 金寨县| 镇坪县| 卢湾区| 昭平县| 海兴县| 大理市| 伊吾县| 醴陵市| 深水埗区| 金寨县| 虞城县| 织金县| 凤山市| 宝应县| 民乐县| 汉阴县| 武山县| 黄陵县| 江口县| 武穴市| 隆安县| 惠州市| 诸暨市| 三门峡市| 梓潼县| 老河口市| 亳州市| 马公市| 红安县| 专栏| 仙游县| 涞源县| 洪洞县| 阜康市| 仁寿县| 聊城市|