roles/agent: add task for determining which wazuh_managers to use through register: yes instead of just grabbing the first one on the list, otherwise fallback to first in the list

This commit is contained in:
neonmei 2020-11-23 11:24:43 -03:00
parent 1dfe0fdb67
commit 332ee7ae8b
No known key found for this signature in database
GPG Key ID: 7EA1832E7E17237E
2 changed files with 8 additions and 0 deletions

View File

@ -92,6 +92,7 @@ wazuh_managers:
api_user: wazuh
max_retries: 5
retry_interval: 5
register: yes
## Enrollment
wazuh_agent_enrollment:

View File

@ -116,6 +116,13 @@
- name: Linux | Agent registration via rest-API
block:
- name: Establish target Wazuh Manager for registration task
set_fact:
target_manager: '{{ manager_primary | length | ternary(manager_primary, manager_fallback) | first }}'
vars:
manager_primary: "{{ wazuh_managers | selectattr('register','true') | list }}"
manager_fallback: "{{ wazuh_managers | list }}"
- name: Linux | Create the agent key via rest-API
uri:
url: "{{ wazuh_managers.0.api_proto }}://{{ wazuh_agent_authd.registration_address }}:{{ wazuh_managers.0.api_port }}/agents/"