Add host exclusion and improve UFW task reliability
Add `excluded` host group and skip offline hosts Fix UFW service initialization command for Alpine Linux
This commit is contained in:
18
homelab.yml
18
homelab.yml
@@ -1,8 +1,24 @@
|
|||||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/playbook.json
|
# yaml-language-server: $schema=https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/playbook.json
|
||||||
---
|
---
|
||||||
- name: Homelab alignment
|
- name: Homelab alignment
|
||||||
hosts: managed
|
hosts: managed:!excluded
|
||||||
become: true
|
become: true
|
||||||
|
gather_facts: false
|
||||||
|
environment:
|
||||||
|
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Test connectivity
|
||||||
|
ansible.builtin.ping:
|
||||||
|
ignore_unreachable: true
|
||||||
|
register: ping_result
|
||||||
|
|
||||||
|
- name: Skip offline hosts
|
||||||
|
ansible.builtin.meta: end_host
|
||||||
|
when: ping_result.unreachable | default(false)
|
||||||
|
|
||||||
|
- name: Gather facts
|
||||||
|
ansible.builtin.setup:
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- role: ufw
|
- role: ufw
|
||||||
|
|||||||
@@ -29,7 +29,5 @@ all:
|
|||||||
damien_hosts:
|
damien_hosts:
|
||||||
|
|
||||||
excluded:
|
excluded:
|
||||||
children:
|
hosts:
|
||||||
hosts:
|
ipfabric:
|
||||||
pve01:
|
|
||||||
ipfabric:
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
- name: Add UFW to default runlevel (Alpine)
|
- name: Add UFW to default runlevel (Alpine)
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: rc-update add ufw default
|
cmd: /sbin/rc-update add ufw default
|
||||||
register: ufw_rc_update_result
|
register: ufw_rc_update_result
|
||||||
changed_when: >- # " >- : transform multiple lines into one line"
|
changed_when: >- # " >- : transform multiple lines into one line"
|
||||||
'already' not in ufw_rc_update_result.stdout
|
'already' not in ufw_rc_update_result.stdout
|
||||||
|
|||||||
Reference in New Issue
Block a user