stop_running_rulebooks.yml.j2

This playbook wil determine the running rulebooks and stop them before configuration, if left running, the configuration will fail with a 'rulebook still running' error.

```yml

  • name: Fixup rulebook activations if EDA config included when:

    • eda_rulebook_activations is defined
    • (eda_rulebook_activations | length) > 0 block:
    • name: Show activations configured ansible.builtin.debug: var: eda_rulebook_activations

    • name: Default set of rulebook activations to stop to empty ansible.builtin.set_fact: rulebook_activations_to_disable: []

    • name: Determine whether we have any enabled activations due to configure ansible.builtin.set_fact: enabled_activation_names: >- {%- for ruleb in eda_rulebook_activations -%} {%- if ruleb.state == 'present' -%} {{ ruleb.name }} {%- if not loop.last -%}, {%- endif -%} {%- endif -%} {%- endfor -%}

    • name: Retrieve existing rulebook activation configs ansible.eda.rulebook_activation_info: aap_hostname: "{{ aap_hostname }}" aap_username: "{{ aap_username }}" aap_password: "{{ aap_password }}" aap_validate_certs: "{{ aap_validate_certs }}" register: rbas

    • name: Filter out enabled and running activations ansible.builtin.set_fact: enabled_running_activations: "{{ rbas.activations | selectattr('is_enabled') | map(attribute='name') }}"

    • name: Work out configured and existing rulebook activations to stop ansible.builtin.set_fact: rulebook_activations_to_disable: "{{ rulebook_activations_to_disable + [ item ] }}" when: item in enabled_running_activations loop: "{{ enabled_activation_names.split(',') }}"

    • name: Disable selected activations for management ansible.eda.rulebook_activation: aap_hostname: "{{ aap_hostname }}" aap_username: "{{ aap_username }}" aap_password: "{{ aap_password }}" aap_validate_certs: "{{ aap_validate_certs }}" name: "{{ item }}" state: disabled

    loop: "{{ enabled_activation_names.split(',') }}"

    loop: "{{ rulebook_activations_to_disable }}"

rescue: - name: Rescue block for error in rulebook activation check ansible.builtin.debug: msg: "Rescuing"

``