Merge pull request #234 from wazuh/233-fix-windows-agent-installation

Fix Wazuh Agent installation on Windows hosts
This commit is contained in:
Manuel J. Bernal 2019-09-11 13:31:46 +02:00 committed by GitHub
commit 39bb001f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 50 deletions

View File

@ -20,14 +20,17 @@ wazuh_notify_time: '10'
wazuh_time_reconnect: '60' wazuh_time_reconnect: '60'
wazuh_crypto_method: 'aes' wazuh_crypto_method: 'aes'
wazuh_winagent_config: wazuh_winagent_config:
install_dir: 'C:\Program Files\ossec-agent\' download_dir: C:\
install_dir_x86: 'C:\Program Files (x86)\ossec-agent\' install_dir: C:\Program Files\ossec-agent\
auth_path: C:\'Program Files'\ossec-agent\agent-auth.exe install_dir_x86: C:\Program Files (x86)\ossec-agent\
auth_path: C:\Program Files\ossec-agent\agent-auth.exe
# Adding quotes to auth_path_x86 since win_shell outputs error otherwise
auth_path_x86: C:\'Program Files (x86)'\ossec-agent\agent-auth.exe auth_path_x86: C:\'Program Files (x86)'\ossec-agent\agent-auth.exe
version: '3.9.5' version: '3.9.5'
revision: '1' revision: '1'
repo: https://packages.wazuh.com/3.x/windows/ repo: https://packages.wazuh.com/3.x/windows/
md5: c3fdbd6c121ca371b8abcd477ed4e8a4 md5: ee5b24216db472d291da4e14f0b3bc63
register_key: 9903C258-FC1E-4886-B7DB-1535976EC1D5
wazuh_agent_config: wazuh_agent_config:
active_response: active_response:
ar_disabled: 'no' ar_disabled: 'no'

View File

@ -2,5 +2,5 @@
- name: restart wazuh-agent - name: restart wazuh-agent
service: name=wazuh-agent state=restarted enabled=yes service: name=wazuh-agent state=restarted enabled=yes
- name: restart wazuh-agent windows - name: Windows | Restart Wazuh Agent
win_service: name=OssecSvc start_mode=auto state=restarted win_service: name=OssecSvc start_mode=auto state=restarted

View File

@ -4,54 +4,50 @@
path: C:\Program Files (x86) path: C:\Program Files (x86)
register: check_path register: check_path
- name: "Set Win Path" - name: Windows | Set Win Path (x86)
set_fact: set_fact:
wazuh_agent_win_path: "{% wazuh_winagent_config.install_dir_x86 if check_path.stat.exists else wazuh_winagent_config.install_dir %}" wazuh_agent_win_path: "{{ wazuh_winagent_config.install_dir_x86 }}"
wazuh_agent_win_auth_path: "{{ wazuh_winagent_config.auth_path_x86 }}"
- name: Windows | Get current installed version
win_shell: "{% if check_path.stat.exists %}{{ wazuh_winagent_config.install_dir_x86 }}{% else %}
{{ wazuh_winagent_config.install_dir }}{% endif %}ossec-agent.exe -h"
args:
removes: "{% if check_path.stat.exists %}{{ wazuh_winagent_config.install_dir_x86 }}{% else %}
{{ wazuh_winagent_config.install_dir }}{% endif %}ossec-agent.exe"
register: agent_version
failed_when: false
changed_when: false
- name: Windows | Check Wazuh agent version installed
set_fact: correct_version=true
when: when:
- agent_version.stdout is defined - check_path.stat.exists
- wazuh_winagent_config.version in agent_version.stdout
- name: Windows | Downloading windows Wazuh agent installer - name: Windows | Set Win Path (x64)
win_get_url: set_fact:
dest: C:\wazuh-agent-installer.msi wazuh_agent_win_path: "{{ wazuh_winagent_config.install_dir }}"
url: "{{ wazuh_winagent_config.repo }}wazuh-agent-{{ wazuh_winagent_config.version }}-{{ wazuh_winagent_config.revision }}.msi" wazuh_agent_win_auth_path: "{{ wazuh_winagent_config.auth_path_x86 }}"
when: when:
- correct_version is not defined - not check_path.stat.exists
- name: Windows | Verify the downloaded Wazuh agent installer - name: Windows | Check if Wazuh installer is already downloaded
win_stat: win_stat:
path: C:\wazuh-agent-installer.msi path: "{{ wazuh_winagent_config.download_dir }}wazuh-agent-{{ wazuh_winagent_config.version }}-{{ wazuh_winagent_config.revision }}.msi"
register: wazuh_package_downloaded
- name: Windows | Download Wazuh Agent package
win_get_url:
url: "{{ wazuh_winagent_config.repo }}wazuh-agent-{{ wazuh_winagent_config.version }}-{{ wazuh_winagent_config.revision }}.msi"
dest: "{{ wazuh_winagent_config.download_dir }}"
when:
- not wazuh_package_downloaded.stat.exists
- name: Windows | Verify the Wazuh Agent installer
win_stat:
path: "{{ wazuh_winagent_config.download_dir }}wazuh-agent-{{ wazuh_winagent_config.version }}-{{ wazuh_winagent_config.revision }}.msi"
get_checksum: true get_checksum: true
checksum_algorithm: md5 checksum_algorithm: md5
register: installer_md5 register: wazuh_agent_status
when:
- correct_version is not defined
failed_when: failed_when:
- installer_md5.stat.checksum != wazuh_winagent_config.md5 - wazuh_agent_status.stat.checksum != wazuh_winagent_config.md5
- name: Windows | Install Wazuh agent - name: Windows | Install Agent if not already installed
win_package: win_package:
path: C:\wazuh-agent-installer.msi path: "{{ wazuh_winagent_config.download_dir }}wazuh-agent-{{ wazuh_winagent_config.version }}-{{ wazuh_winagent_config.revision }}.msi"
when: product_id: '{{ "{" }}{{ wazuh_winagent_config.register_key }}{{ "}" }}'
- correct_version is not defined state: present
- name: Windows | Check if client.keys exists - name: Windows | Check if client.keys exists
win_stat: path="{{ wazuh_agent_win_path }}" win_stat: path="{{ wazuh_agent_win_path }}client.keys"
register: check_windows_key register: check_windows_key
notify: restart wazuh-agent windows
tags: tags:
- config - config
@ -62,15 +58,12 @@
- name: Windows | Register agent - name: Windows | Register agent
win_shell: > win_shell: >
{% if check_path.stat.exists %}{{ wazuh_winagent_config.auth_path_x86 }}{% else %} {{ wazuh_agent_win_auth_path }}
{{ wazuh_winagent_config.auth_path }}{% endif %}
-m {{ wazuh_managers.0.address }} -m {{ wazuh_managers.0.address }}
-p {{ wazuh_agent_authd.port }} -p {{ wazuh_agent_authd.port }}
{% if authd_pass is defined %} -P {{ authd_pass }}{% endif %} {% if authd_pass is defined %} -P {{ authd_pass }}{% endif %}
args:
chdir: "{{ wazuh_agent_win_path }}"
register: agent_auth_output register: agent_auth_output
notify: restart wazuh-agent windows notify: Windows | Restart Wazuh Agent
when: when:
- wazuh_agent_authd.enable - wazuh_agent_authd.enable
- not check_windows_key.stat.exists or check_windows_key.stat.size == 0 - not check_windows_key.stat.exists or check_windows_key.stat.size == 0
@ -78,11 +71,16 @@
tags: tags:
- config - config
- name: Windows | Check if ossec folder is accessible
win_file:
path: "{{ wazuh_agent_win_path }}"
state: directory
- name: Windows | Installing agent configuration (ossec.conf) - name: Windows | Installing agent configuration (ossec.conf)
win_template: template:
src: var-ossec-etc-ossec-agent.conf.j2 src: var-ossec-etc-ossec-agent.conf.j2
dest: "{{ wazuh_agent_win_path }}ossec.conf" dest: "{{ wazuh_agent_win_path }}ossec.conf"
notify: restart wazuh-agent windows notify: Windows | Restart Wazuh Agent
tags: tags:
- config - config
@ -90,11 +88,11 @@
win_template: win_template:
src: var-ossec-etc-local-internal-options.conf.j2 src: var-ossec-etc-local-internal-options.conf.j2
dest: "{{ wazuh_agent_win_path }}local_internal_options.conf" dest: "{{ wazuh_agent_win_path }}local_internal_options.conf"
notify: restart wazuh-agent windows notify: Windows | Restart Wazuh Agent
tags: tags:
- config - config
- name: Windows | Delete downloaded Wazuh agent installer file - name: Windows | Delete downloaded Wazuh agent installer file
win_file: win_file:
path: C:\wazuh-agent-installer.msi path: "{{ wazuh_winagent_config.download_dir }}wazuh-agent-{{ wazuh_winagent_config.version }}-{{ wazuh_winagent_config.revision }}.msi"
state: absent state: absent

View File

@ -322,7 +322,8 @@
notify: restart wazuh-api notify: restart wazuh-api
when: when:
- wazuh_api_user is defined - wazuh_api_user is defined
- not (ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat' or ansible_distribution == 'Amazon' and ansible_distribution_major_version|int < 6) - not (ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat' or ansible_distribution == 'Amazon')
- ansible_distribution_major_version|int < 6
tags: tags:
- config - config
@ -378,7 +379,8 @@
environment: environment:
LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:/var/ossec/framework/lib" LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:/var/ossec/framework/lib"
when: when:
- not (ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat' or ansible_distribution == 'Amazon' and ansible_distribution_major_version|int < 6) - not (ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat' or ansible_distribution == 'Amazon')
- ansible_distribution_major_version|int < 6
- name: Ensure Wazuh Manager is started and enabled (EL5) - name: Ensure Wazuh Manager is started and enabled (EL5)
service: service: