上QQ阅读APP看书,第一时间看更新
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]
...