roles/agent: refresh agent validation in rest registration method

This commit is contained in:
neonmei 2020-11-23 11:29:34 -03:00
parent d4092bf686
commit a4c4b6cd32
No known key found for this signature in database
GPG Key ID: 7EA1832E7E17237E

View File

@ -168,23 +168,27 @@
- config - config
- api - api
- name: Linux | Retrieve new agent data via rest-API - name: Linux | Validate registered agent key matches manager record
uri: uri:
url: >- url: '{{ target_manager.api_proto }}://{{ target_manager.address }}:{{ target_manager.api_port }}/agents/{{ agent_id }}/key'
"{{ wazuh_managers.0.api_proto }}://{{ wazuh_agent_authd.registration_address
}}:{{ wazuh_managers.0.api_port }}/agents/{{ newagent_api.json.data.id }}"
validate_certs: false
method: GET method: GET
return_content: true headers:
user: "{{ wazuh_managers.0.api_user }}" Authorization: 'Bearer {{ jwt_token }}'
password: "{{ api_pass }}" status_code: 200
when: return_content: yes
- not check_keys.stat.exists or check_keys.stat.size == 0 validate_certs: '{{ target_manager.validate_certs | default(false) }}'
- wazuh_agent_authd.registration_address is not none
- newagent_api.json.error == 0
register: newagentdata_api
delegate_to: "{{ 'localhost' if not wazuh_api_reachable_from_agent else inventory_hostname }}"
become: no become: no
no_log: '{{ wazuh_agent_nolog_sensible | bool }}'
delegate_to: "{{ 'localhost' if not wazuh_api_reachable_from_agent else inventory_hostname }}"
register: api_agent_validation
vars:
agent_id: '{{ api_agent_post.json.data.id }}'
agent_key: '{{ api_agent_post.json.data.key }}'
jwt_token: '{{ api_jwt_result.json.data.token }}'
failed_when: api_agent_validation.json.data.affected_items[0].key != agent_key
when:
- wazuh_agent_api_validate | bool
- api_agent_post.json.error == 0
tags: tags:
- config - config
- api - api