Copied from the environment repository's local role. The files are identical except: galaxy namespace mortis; comments, argument_specs descriptions and the README scrubbed of environment references (issue numbers, CI runs, playbooks, inventory paths and groups, scripts and caller roles by name), with the technical explanation kept and reworded generically; the stray-variable guard's fail message drops its issue reference; the molecule scenario calls the role by its FQCN (mortis.kamino.ufw), follows the Kamino scenario conventions (kamino-molecule header, scenario.test_sequence) and no longer sets ANSIBLE_COLLECTIONS_PATH or ANSIBLE_ROLES_PATH. No variable, default, argument_specs type or task logic changed; the test coverage is the same. The README follows the other Kamino roles: purpose, the main, service_rules and orphan_rules entry points, variables, and example plays with the FQCN and tasks_from. The meta licence stays GPL-3.0-or-later AND GPL-3.0-only (templates/before.rules.j2 is derived from ufw's own file, already annotated in REUSE.toml and NOTICE). galaxy.yml's dependency comment names ufw as a community.general user. Not verified locally: the molecule scenario (it runs on the kamino-molecule runner in CI) and ansible-test sanity. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
38 lines
1.4 KiB
YAML
38 lines
1.4 KiB
YAML
---
|
|
- name: Check whether ufw sysctl.conf exists
|
|
become: true
|
|
ansible.builtin.stat:
|
|
path: /etc/ufw/sysctl.conf
|
|
register: ufw_sysctl_stat
|
|
check_mode: false
|
|
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
|
|
|
# ansible_check_mode is not used: the play-level `check_mode: true` keyword does not set that
|
|
# magic variable inside include_role tasks (only --check does). A command task
|
|
# is skipped in both forms and its result says so, the same probe as tasks/service_rules.yml.
|
|
- name: Probe whether the run is in check mode
|
|
ansible.builtin.command: "true"
|
|
register: ufw_sysctl_probe
|
|
changed_when: false
|
|
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
|
|
|
- name: Remember whether the run is in check mode
|
|
ansible.builtin.set_fact:
|
|
ufw_sysctl_check: "{{ ufw_sysctl_probe is skipped }}"
|
|
when: ufw_enabled and ufw_sysctl_overrides | length > 0
|
|
|
|
# In check mode on a fresh host ufw is not installed yet, so the file is absent.
|
|
- name: Set sysctl overrides in ufw sysctl.conf
|
|
become: true
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/ufw/sysctl.conf
|
|
regexp: '^#?\s*{{ ufw_sysctl_override.name }}='
|
|
line: "{{ ufw_sysctl_override.name }}={{ ufw_sysctl_override.value }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
loop: "{{ ufw_sysctl_overrides }}"
|
|
loop_control:
|
|
loop_var: ufw_sysctl_override
|
|
when: ufw_enabled and (ufw_sysctl_stat.stat.exists or not ufw_sysctl_check)
|