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

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]
...
主站蜘蛛池模板: 托克托县| 曲靖市| 克东县| 辰溪县| 德钦县| 德阳市| 宝兴县| 佛冈县| 泾源县| 合川市| 彭山县| 枣阳市| 营口市| 中江县| 铁岭县| 洛浦县| 玉林市| 辽源市| 仁寿县| 巍山| 夏津县| 新乐市| 邵阳县| 隆尧县| 汉川市| 华蓥市| 栾城县| 沭阳县| 兴海县| 永城市| 常德市| 云浮市| 西华县| 宝兴县| 江口县| 林芝县| 呼图壁县| 临沭县| 阳新县| 永州市| 玉溪市|