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
+4
View File
@@ -12,6 +12,10 @@ crowdsec:
scenarios: {} scenarios: {}
# path below /etc/crowdsec -> content, for local parsers and scenarios. # path below /etc/crowdsec -> content, for local parsers and scenarios.
local_files: {} local_files: {}
# name -> installed hub scenario removed from the agent (null drops one); needed where a local scenario replaces it.
disabled_scenarios: {}
# name -> path below /etc/crowdsec of a retired local file, removed when present (null drops one).
absent_files: {}
# name -> CIDR (single addresses as /32 or /128) never acted upon. Joined by # name -> CIDR (single addresses as /32 or /128) never acted upon. Joined by
# the public_ips (same format) of every inventory host, then whitelisted by # the public_ips (same format) of every inventory host, then whitelisted by
# this agent and, when lapi_allowlist is set, allowlisted on the LAPI. # this agent and, when lapi_allowlist is set, allowlisted on the LAPI.
+27
View File
@@ -171,6 +171,24 @@
when: crowdsec_missing | length > 0 when: crowdsec_missing | length > 0
notify: Restart crowdsec 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 - name: Install the local parsers and scenarios
ansible.builtin.copy: ansible.builtin.copy:
dest: "/etc/crowdsec/{{ item.key }}" dest: "/etc/crowdsec/{{ item.key }}"
@@ -181,6 +199,15 @@
label: "{{ item.key }}" label: "{{ item.key }}"
notify: Restart crowdsec 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 - name: Enable the agent and the bouncer
ansible.builtin.systemd: ansible.builtin.systemd:
name: "{{ item }}" name: "{{ item }}"