Add EDA (Event Driven Ansible)
Not every organization is able, or even qualified to use Event Driven Asnsible for whatever business reason.
So we do not add this by default to an organization, we add this when needed or even create a separate organization to handle EDA playbooks and events.
So I chose to create a separate organization and added the eda files to this organization.
This can be automated and I will probably do that lateron in the process, for now I add them manually.
The files
Add the following files to the exsisting files in every group_vars directory:
eda_controller_tokens.yml
eda_credentials.yml
eda_event_streams.yml
eda_projects.yml
eda_rulebook_activations.yml
Change code in main.yml
Add the following code to the main.yml: below the controller_workflows entry in the set_fact.
eda_controller_tokens: >
{{ eda_controller_tokens_all |
community.general.lists_mergeby(vars['eda_controller_tokens_' + branch_name],
'name', recursive=true, list_merge='append') }}
eda_credentials: >
{{ eda_credentials_all |
community.general.lists_mergeby(vars['eda_credentials_' + branch_name],
'name', recursive=true, list_merge='append') }}
eda_decision_environments: >
{{ eda_decision_environments_all |
community.general.lists_mergeby(vars['eda_decision_environments_' + branch_name],
'name', recursive=true, list_merge='append') }}
eda_event_streams: >
{{ eda_event_streams_all |
community.general.lists_mergeby(vars['eda_event_streams_' + branch_name],
'name', recursive=true, list_merge='append') }}
eda_projects: >
{{ eda_projects_all |
community.general.lists_mergeby(vars['eda_projects_' + branch_name],
'name', recursive=true, list_merge='append') }}
eda_rulebook_activations: >
{{ eda_rulebook_activations_all |
community.general.lists_mergeby(vars['eda_rulebook_activations_' + branch_name],
'name', recursive=true, list_merge='append') }}
- name: Do fixups for activation rulebooks if needed
ansible.builtin.include_tasks: stop_running_rulebooks.yml
This is all that is needed to use config as code in Automation platform Event Driven Ansible.
The above code is as it runs in my lab environment (exept the secrets).
The Configuration as code can only apply changes, or run flawlessly, when no rulebooks from this
configuration are active, so we must determine which are active and stop these temporarily.
This is done by the following playbook:
I found this as a role, using a custom filter plugin, I rewrote the code so the thing done by the filter plugin is now done with jinja inside the play itself. For me that is more readable than a separate filter plugin.
stop_running_rulebooks.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"
The configuration as code for EDA shoould run without any problems now.
The project that is configured with this config, is found here:
EDA_example_project