crowdsec: disabled_scenarios removes hub scenarios replaced by local ones, absent_files removes retired local files

This commit is contained in:
2026-10-26 10:23:28 +00:00
parent fee8ec1ff6
commit 2b293e9835
2 changed files with 31 additions and 0 deletions
+27
View File
@@ -171,6 +171,24 @@
when: crowdsec_missing | length > 0
notify: Restart crowdsec
# Read again: the collections installed above bring their scenarios along.
- name: List the installed hub scenarios
ansible.builtin.command: cscli hub list -o json
register: crowdsec_scenarios_json
changed_when: false
failed_when: crowdsec_scenarios_json.rc != 0 and not ansible_check_mode
check_mode: false
# --force also removes items that belong to an installed collection. A plain "cscli hub upgrade" keeps them removed;
# "cscli hub upgrade --force" would bring them back.
- name: Remove the hub scenarios replaced by local ones
ansible.builtin.command: "cscli scenarios remove {{ item.value }} --force"
loop: "{{ crowdsec.disabled_scenarios | dict2items | rejectattr('value', 'none') }}"
loop_control:
label: "{{ item.value }}"
when: item.value in ((crowdsec_scenarios_json.stdout | default('{}', true) | from_json).scenarios | default([], true) | map(attribute='name'))
notify: Restart crowdsec
- name: Install the local parsers and scenarios
ansible.builtin.copy:
dest: "/etc/crowdsec/{{ item.key }}"
@@ -181,6 +199,15 @@
label: "{{ item.key }}"
notify: Restart crowdsec
- name: Remove retired local files
ansible.builtin.file:
path: "/etc/crowdsec/{{ item.value }}"
state: absent
loop: "{{ crowdsec.absent_files | dict2items | rejectattr('value', 'none') }}"
loop_control:
label: "{{ item.value }}"
notify: Restart crowdsec
- name: Enable the agent and the bouncer
ansible.builtin.systemd:
name: "{{ item }}"