make agent registration delegate_to configurable

Registering to the API requires the port 55000 of the wazuh manager is
open. Depending on the firewall policy, it may be true from the
ansible controller, reason why it was delegated to localhost in the
original implementation at 6cb6d3bda8

The role should be more flexible and allow for the API call to be made
from the ansible controller or the host.

Implementation note: although it would be more elegant to use omit
instead of inventory_hostname, it is not possible because of an
ansible bug at this time https://github.com/ansible/ansible/issues/26009

Fixes: https://github.com/wazuh/wazuh-ansible/issues/126

Signed-off-by: singuliere <singuliere@autistici.org>
This commit is contained in:
singuliere 2019-01-08 13:58:41 +01:00
parent 9327f052de
commit 7cce8e9490
No known key found for this signature in database
GPG Key ID: 900857755EF189C2
2 changed files with 4 additions and 2 deletions

View File

@ -6,6 +6,7 @@ wazuh_managers:
api_port: 55000
api_proto: 'http'
api_user: null
wazuh_api_reachable_from_agent: false
wazuh_profile: null
wazuh_auto_restart: 'yes'
wazuh_agent_authd:

View File

@ -95,11 +95,12 @@
user: "{{ wazuh_managers.0.api_user }}"
password: "{{ api_pass }}"
register: newagent_api
delegate_to: "{{ 'localhost' if not wazuh_api_reachable_from_agent else inventory_hostname }}"
become: no
changed_when: newagent_api.json.error == 0
when:
- check_keys.stat.exists == false or check_keys.stat.size == 0
- wazuh_managers.0.address is not none
become: no
tags:
- config
- api
@ -117,7 +118,7 @@
- wazuh_managers.0.address is not none
- newagent_api.json.error == 0
register: newagentdata_api
delegate_to: localhost
delegate_to: "{{ 'localhost' if not wazuh_api_reachable_from_agent else inventory_hostname }}"
become: no
tags:
- config