Ansible: Playbook para desinstalar apache e firewall
Estrutura dos arquivos:
[root@ansible-master Projeto2_managing_includes]# tree
.
├── ansible.cfg
├── desinstall-playbook.yml
├── inventory
├── playbook.yml
├── tasks
│ └── enviroment.yaml
└── vars
└── variables.yml
2 directories, 6 files
Arquivo variables.yml
firewall_pkg: firewalld
firewall_svc: firewalld
web_pkg: httpd
web_svc: http
Playbook para desinstalar serviços:
---
- name: Desinstall playbook web
hosts: web-hosts
vars_files:
- vars/variables.yml
tasks:
- name: Remove index file
file:
path: /var/www/html/index.html
state: absent
- name: Daemon reload
systemd:
name: "{{ item }}"
state: stopped
daemon_reload: yes
with_items:
- "{{ firewall_pkg }}"
- "{{ web_pkg }}"
register: var
- name: register var
debug: msg="{{ var }}"
- name: Remove web service and firewalld
yum:
name:
- "{{ firewall_pkg }}"
- "{{ web_pkg }}"
state: absent
Execução e saÃda:
[root@ansible-master Projeto2_managing_includes]# ansible-playbook desinstall-playbook.yml
PLAY [Desinstall playbook web] *************************************************************************
TASK [Gathering Facts] *********************************************************************************
ok: [172.25.250.21]
TASK [Remove index file] *******************************************************************************
changed: [172.25.250.21]
TASK [Daemon reload] ***********************************************************************************
changed: [172.25.250.21] => (item=firewalld)
changed: [172.25.250.21] => (item=httpd)
TASK [register var] ************************************************************************************
ok: [172.25.250.21] => {
"msg": {
"changed": true,
"msg": "All items completed",
"results": [
.................
TASK [Remove web service and firewalld] ****************************************************************
changed: [172.25.250.21]
PLAY RECAP *********************************************************************************************
172.25.250.21 : ok=5 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
No comments