From 2b4a1407a5f804bd502391ad24a79fa786ff93bf Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 14 Nov 2019 19:11:28 +0100 Subject: [PATCH 01/89] Add variables for sources installation --- roles/wazuh/ansible-wazuh-agent/defaults/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index 4060e99c..e8e5c83c 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -33,6 +33,8 @@ wazuh_winagent_config: md5: 71650780904cbfc2e45eae4298adb7a3 wazuh_agent_config: repo: + sources: false + sources_branch: "3.10" apt: 'deb https://packages.wazuh.com/3.x/apt/ stable main' yum: 'https://packages.wazuh.com/3.x/yum/' gpg: 'https://packages.wazuh.com/key/GPG-KEY-WAZUH' From 8e56076b9fc8e4200a4dadd5dfbf67943844ec5f Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 14 Nov 2019 19:11:59 +0100 Subject: [PATCH 02/89] Add conditionals to disable repo installation and install from sources --- roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml | 7 +++++++ roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml index 1aa7a38e..cd7f3d77 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml @@ -1,4 +1,9 @@ --- + +- include_tasks: "installation_from_sources" + when: + - wazuh_agent_config.repo.sources == "true" + - name: Debian/Ubuntu | Install apt-transport-https and ca-certificates apt: name: @@ -33,6 +38,8 @@ repo: "{{ wazuh_agent_config.repo.apt }}" state: present update_cache: true + when: + - wazuh_agent_config.repo.sources == "false" - name: Debian/Ubuntu | Set Distribution CIS filename for debian set_fact: diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml index 8f3b8dbd..1aa909fa 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml @@ -1,4 +1,9 @@ --- + +- include_tasks: "installation_from_sources" + when: + - wazuh_agent_config.repo.sources == "true" + - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: name: wazuh_repo @@ -10,6 +15,7 @@ when: - (ansible_facts['os_family']|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) + - wazuh_agent_config.repo.sources == "false" register: repo_v5_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo @@ -22,6 +28,7 @@ changed_when: false when: - repo_v5_installed is skipped + - wazuh_agent_config.repo.sources == "false" - name: RedHat/CentOS/Fedora | download Oracle Java RPM get_url: From a3f4ed74eaf8b7c87fa5a10db306c50f8a026f53 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 14 Nov 2019 19:12:22 +0100 Subject: [PATCH 03/89] Add installation_from_sources.yml tasks --- .../tasks/installation_from_sources.yml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml new file mode 100644 index 00000000..f068353c --- /dev/null +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -0,0 +1,59 @@ +--- + - hosts: all + tasks: + - include_vars: ../defaults/main.yml + - name: Install dependencies to build Wazuh packages + package: + name: + - make + - gcc + - policycoreutils-python-utils + - automake + - autoconf + - libtool + state: present + + - name: Download required packages from github.com/wazuh/wazuh + get_url: + url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_agent_config.repo.sources_branch }}.tar.gz" + dest: "/tmp/{{ wazuh_agent_config.repo.sources_branch }}.tar.gz" + delegate_to: "{{ inventory_hostname }}" + + - name: Extract downloaded Wazuh branch from Github + unarchive: + src: "/tmp/{{ wazuh_agent_config.repo.sources_branch }}.tar.gz" + dest: "/tmp/" + remote_src: yes + + - name: Configure "preloaded_vars.conf" file + copy: + dest: "/tmp/wazuh-{{ wazuh_agent_config.repo.sources_branch }}/etc/preloaded-vars.conf" + content: | + USER_LANGUAGE="en" + USER_NO_STOP="y" + USER_INSTALL_TYPE="agent" + USER_DIR="/var/ossec" + USER_ENABLE_SYSCHECK="y" + USER_ENABLE_ROOTCHECK="y" + USER_ENABLE_OPENSCAP="y" + USER_ENABLE_ACTIVE_RESPONSE="y" + USER_AGENT_SERVER_IP="{{ wazuh_managers.0.address }}" + USER_CA_STORE="/var/ossec/wpk_root.pem" + USER_ENABLE_SCA="y" + force: yes + + - name: Clean remaining files from others builds + command: "make -C src {{ item }}" + args: + chdir: "/tmp/wazuh-{{ wazuh_agent_config.repo.sources_branch }}/src/" + with_items: + - "clean" + - "clean-deps" + failed_when: false + + - name: Executing "install.sh" script to build and install the Wazuh Agent + shell: ./install.sh + args: + chdir: "/tmp/wazuh-{{ wazuh_agent_config.repo.sources_branch }}" + + become: yes From df016d53c6173512f790cba1e95e8d7a6a1f81e2 Mon Sep 17 00:00:00 2001 From: Jose M Date: Fri, 15 Nov 2019 16:39:12 +0100 Subject: [PATCH 04/89] Add variables for wazuh installation from sources --- .../ansible-wazuh-agent/defaults/main.yml | 22 +++++++++++++++-- .../ansible-wazuh-manager/defaults/main.yml | 24 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index e8e5c83c..58db0f85 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -1,5 +1,25 @@ --- wazuh_agent_version: 3.10.2-1 +wazuh_sources_installation: + enabled: "true" + branch: "3.10" + user_language: "y" + user_no_stop: "y" + user_install_type: "agent" + user_dir: "/var/ossec" + user_delete_dir: "y" + user_enable_active_response: "y" + user_enable_syscheck: "y" + user_enable_rootcheck: "y" + user_enable_openscap: "y" + user_enable_authd: null + user_generate_authd_cert: null + user_update: null + user_binaryinstall: null + user_agent_server_ip: null + user_agent_server_name: null + user_agent_config_profile: null + wazuh_managers: - address: 127.0.0.1 port: 1514 @@ -33,8 +53,6 @@ wazuh_winagent_config: md5: 71650780904cbfc2e45eae4298adb7a3 wazuh_agent_config: repo: - sources: false - sources_branch: "3.10" apt: 'deb https://packages.wazuh.com/3.x/apt/ stable main' yum: 'https://packages.wazuh.com/3.x/yum/' gpg: 'https://packages.wazuh.com/key/GPG-KEY-WAZUH' diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index e66ccae5..924bd980 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -4,6 +4,30 @@ wazuh_manager_version: 3.10.2-1 wazuh_manager_fqdn: "wazuh-server" wazuh_manager_package_state: present +wazuh_sources_installation: + enabled: false + branch: "3.10" + user_language: "y" + user_no_stop: "y" + user_install_type: "manager" + user_dir: "/var/ossec" + user_delete_dir: "y" + user_enable_active_response: "y" + user_enable_syscheck: "y" + user_enable_rootcheck: "y" + user_enable_openscap: "y" + user_enable_authd: "y" + user_generate_authd_cert: "n" + user_update: null + user_binaryinstall: null + user_enable_email: null + user_auto_start: null + user_email_address: null + user_email_smpt: null + user_enable_syslog: null + user_white_list: null + user_ca_store: null + wazuh_manager_config: repo: apt: 'deb https://packages.wazuh.com/3.x/apt/ stable main' From 46b4d34695094e1066f8cebaf7e3a14e78938e4f Mon Sep 17 00:00:00 2001 From: Jose M Date: Fri, 15 Nov 2019 16:41:28 +0100 Subject: [PATCH 05/89] Update conditionals to use new variables --- roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml | 4 ++-- roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml | 10 ++++++++-- roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml | 6 +++--- roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml | 6 ++++++ roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 3 +++ roles/wazuh/ansible-wazuh-manager/tasks/main.yml | 8 ++++++-- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml index cd7f3d77..5e2cfae6 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml @@ -2,7 +2,7 @@ - include_tasks: "installation_from_sources" when: - - wazuh_agent_config.repo.sources == "true" + - wazuh_sources_installation.enabled - name: Debian/Ubuntu | Install apt-transport-https and ca-certificates apt: @@ -39,7 +39,7 @@ state: present update_cache: true when: - - wazuh_agent_config.repo.sources == "false" + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Set Distribution CIS filename for debian set_fact: diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml index 2ef87f11..3a745a20 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml @@ -13,6 +13,7 @@ poll: 30 when: - ansible_os_family|lower == "redhat" + - not wazuh_sources_installation.enabled tags: - init @@ -23,6 +24,7 @@ cache_valid_time: 3600 when: - ansible_os_family|lower != "redhat" + - not wazuh_sources_installation.enabled tags: - init @@ -192,7 +194,11 @@ tags: config - include_tasks: "RMRedHat.yml" - when: ansible_os_family == "RedHat" + when: + - ansible_os_family == "RedHat" + - not wazuh_sources_installation.enabled - include_tasks: "RMDebian.yml" - when: ansible_os_family == "Debian" + when: + - ansible_os_family == "Debian" + - not wazuh_sources_installation.enabled diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml index 1aa909fa..a81ecea5 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml @@ -2,7 +2,7 @@ - include_tasks: "installation_from_sources" when: - - wazuh_agent_config.repo.sources == "true" + - wazuh_sources_installation.enabled - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: @@ -15,7 +15,7 @@ when: - (ansible_facts['os_family']|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) - - wazuh_agent_config.repo.sources == "false" + - not wazuh_sources_installation.enabled register: repo_v5_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo @@ -28,7 +28,7 @@ changed_when: false when: - repo_v5_installed is skipped - - wazuh_agent_config.repo.sources == "false" + - not wazuh_sources_installation.enabled - name: RedHat/CentOS/Fedora | download Oracle Java RPM get_url: diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index b7bc7946..fc3a646f 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -23,12 +23,14 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Installing Wazuh repository key apt_key: url: "{{ wazuh_manager_config.repo.gpg }}" when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Add Wazuh repositories apt_repository: @@ -37,6 +39,8 @@ state: present update_cache: true changed_when: false + when: + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Installing NodeJS repository key (Ubuntu 14) become: true @@ -126,3 +130,5 @@ register: wazuh_manager_main_packages_installed until: wazuh_manager_main_packages_installed is succeeded tags: init + when: + - not wazuh_sources_installation.enabled diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index c8e8a95a..2a76fb45 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -41,6 +41,7 @@ when: - (ansible_os_family|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) + - not wazuh_sources_installation.enabled register: repo_v5_manager_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo @@ -53,6 +54,7 @@ changed_when: false when: - repo_v5_manager_installed is skipped + - not wazuh_sources_installation.enabled - name: RedHat/CentOS/Fedora | Install openscap package: name={{ item }} state=present @@ -149,6 +151,7 @@ until: wazuh_manager_main_packages_installed is succeeded when: - ansible_os_family|lower == "redhat" + - not wazuh_sources_installation.enabled tags: - init diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index ed4847aa..901ec050 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -354,7 +354,11 @@ - ansible_distribution in ['CentOS', 'RedHat', 'Amazon'] and ansible_distribution_major_version|int < 6 - include_tasks: "RMRedHat.yml" - when: ansible_os_family == "RedHat" or ansible_os_family == "Amazon" + when: + - ansible_os_family == "RedHat" or ansible_os_family == "Amazon" + - not wazuh_sources_installation.enabled - include_tasks: "RMDebian.yml" - when: ansible_os_family == "Debian" + when: + - ansible_os_family == "Debian" + - not wazuh_sources_installation.enabled From 8ecbeff501b403ba9c7bc611a4f89d46763219b3 Mon Sep 17 00:00:00 2001 From: Jose M Date: Fri, 15 Nov 2019 16:42:27 +0100 Subject: [PATCH 06/89] Update installation_from_sources.yml. Added installation conditionals --- .../tasks/installation_from_sources.yml | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index f068353c..bdfc9676 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -7,53 +7,59 @@ name: - make - gcc - - policycoreutils-python-utils - automake - autoconf - libtool state: present + - name: Installing policycoreutils-python (RedHat families) + package: + name: + - policycoreutils-python + when: + - ansible_os_family|lower == "redhat" + + - name: Installing policycoreutils-python-utils (Debian families) + package: + name: + - libc6-dev + - curl + - policycoreutils + when: + - ansible_os_family|lower == "debian" + - name: Download required packages from github.com/wazuh/wazuh get_url: - url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_agent_config.repo.sources_branch }}.tar.gz" - dest: "/tmp/{{ wazuh_agent_config.repo.sources_branch }}.tar.gz" + url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_sources_installation.branch }}.tar.gz" + dest: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" delegate_to: "{{ inventory_hostname }}" - name: Extract downloaded Wazuh branch from Github unarchive: - src: "/tmp/{{ wazuh_agent_config.repo.sources_branch }}.tar.gz" + src: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" dest: "/tmp/" remote_src: yes - - name: Configure "preloaded_vars.conf" file - copy: - dest: "/tmp/wazuh-{{ wazuh_agent_config.repo.sources_branch }}/etc/preloaded-vars.conf" - content: | - USER_LANGUAGE="en" - USER_NO_STOP="y" - USER_INSTALL_TYPE="agent" - USER_DIR="/var/ossec" - USER_ENABLE_SYSCHECK="y" - USER_ENABLE_ROOTCHECK="y" - USER_ENABLE_OPENSCAP="y" - USER_ENABLE_ACTIVE_RESPONSE="y" - USER_AGENT_SERVER_IP="{{ wazuh_managers.0.address }}" - USER_CA_STORE="/var/ossec/wpk_root.pem" - USER_ENABLE_SCA="y" - force: yes - - name: Clean remaining files from others builds command: "make -C src {{ item }}" args: - chdir: "/tmp/wazuh-{{ wazuh_agent_config.repo.sources_branch }}/src/" + chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/src/" with_items: - "clean" - "clean-deps" - failed_when: false + failed_when: false + + - name: Render the "preloaded-vars.conf" file + template: + src: ../templates/preloaded_vars.conf.j2 + dest: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/etc/preloaded-vars.conf" + owner: root + group: root + mode: '644' - name: Executing "install.sh" script to build and install the Wazuh Agent shell: ./install.sh args: - chdir: "/tmp/wazuh-{{ wazuh_agent_config.repo.sources_branch }}" + chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" become: yes From 6a0c92294e0f08644a538f4ebb68771d3d21c2db Mon Sep 17 00:00:00 2001 From: Jose M Date: Fri, 15 Nov 2019 16:42:40 +0100 Subject: [PATCH 07/89] Implement template for preloaded_vars.conf --- .../ansible-wazuh-agent/templates/preloaded_vars.conf.j2 | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 diff --git a/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 b/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 new file mode 100644 index 00000000..f02252d1 --- /dev/null +++ b/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 @@ -0,0 +1,7 @@ +{% for key, value in wazuh_sources_installation.items() %} +{% if "user_" in key %} +{% if value is defined and value is not none %} +{{ key|upper }}="{{ value }}" +{% endif %} +{% endif %} +{% endfor %} \ No newline at end of file From b3a2fea6b94616726e2d6250915eb71b55fc1285 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 18 Nov 2019 16:04:00 +0100 Subject: [PATCH 08/89] UPdate wazuh-agent default settings related to sources_installation --- roles/wazuh/ansible-wazuh-agent/defaults/main.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index 58db0f85..886de1bb 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -12,13 +12,15 @@ wazuh_sources_installation: user_enable_syscheck: "y" user_enable_rootcheck: "y" user_enable_openscap: "y" - user_enable_authd: null - user_generate_authd_cert: null + user_enable_sca: "y" + user_enable_authd: "y" + user_generate_authd_cert: "n" user_update: null user_binaryinstall: null - user_agent_server_ip: null + user_agent_server_ip: "172.16.1.2" user_agent_server_name: null user_agent_config_profile: null + user_ca_store: "/var/ossec/wpk_root.pem" wazuh_managers: - address: 127.0.0.1 From c1b331be79ef28cb4bb768d45879523009f9777a Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 18 Nov 2019 16:04:13 +0100 Subject: [PATCH 09/89] Update Wazuh Manager default vars related to sources installation --- .../ansible-wazuh-manager/defaults/main.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 924bd980..9df70863 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -5,11 +5,11 @@ wazuh_manager_fqdn: "wazuh-server" wazuh_manager_package_state: present wazuh_sources_installation: - enabled: false + enabled: true branch: "3.10" - user_language: "y" + user_language: "en" user_no_stop: "y" - user_install_type: "manager" + user_install_type: "server" user_dir: "/var/ossec" user_delete_dir: "y" user_enable_active_response: "y" @@ -17,16 +17,17 @@ wazuh_sources_installation: user_enable_rootcheck: "y" user_enable_openscap: "y" user_enable_authd: "y" - user_generate_authd_cert: "n" + user_generate_authd_cert: null user_update: null user_binaryinstall: null - user_enable_email: null - user_auto_start: null + user_enable_email: "n" + user_auto_start: "y" user_email_address: null user_email_smpt: null - user_enable_syslog: null - user_white_list: null + user_enable_syslog: "n" + user_white_list: "n" user_ca_store: null + threads: "2" wazuh_manager_config: repo: From 9258026c49400e23f2c7247ac6dd89ef57331752 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 19 Nov 2019 12:08:42 +0100 Subject: [PATCH 10/89] Update installation_from_sources.yml to pass linting --- .../tasks/installation_from_sources.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index bdfc9676..d45c4219 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -33,7 +33,7 @@ url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_sources_installation.branch }}.tar.gz" dest: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" delegate_to: "{{ inventory_hostname }}" - + - name: Extract downloaded Wazuh branch from Github unarchive: src: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" @@ -47,19 +47,22 @@ with_items: - "clean" - "clean-deps" - failed_when: false + register: clean_result + changed_when: clean_result.rc == 0 + failed_when: false - name: Render the "preloaded-vars.conf" file template: - src: ../templates/preloaded_vars.conf.j2 + src: /templates/preloaded_vars.conf.j2 dest: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/etc/preloaded-vars.conf" owner: root group: root mode: '644' - - name: Executing "install.sh" script to build and install the Wazuh Agent - shell: ./install.sh + - name: Executing "install.sh" script to build and install the Wazuh Manager + shell: ./install.sh > /tmp/build_log.txt + register: installation_result + changed_when: installation_result == 0 args: chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" - - become: yes + become: yes \ No newline at end of file From b467a9e5c77278c2a66601fc8d7116019baf91ee Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 19 Nov 2019 12:09:10 +0100 Subject: [PATCH 11/89] Fix linting for "Linux.yml" tasks in Wazuh Agent --- roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml index 3a745a20..5cd95ff4 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml @@ -194,11 +194,11 @@ tags: config - include_tasks: "RMRedHat.yml" - when: + when: - ansible_os_family == "RedHat" - not wazuh_sources_installation.enabled - include_tasks: "RMDebian.yml" - when: + when: - ansible_os_family == "Debian" - not wazuh_sources_installation.enabled From cbc5de68acb955441358ad33b4f2144770f83489 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 19 Nov 2019 12:09:56 +0100 Subject: [PATCH 12/89] Set "delete_dir" and "enable_active_response" to null in manager default --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 9df70863..ab652cc2 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -11,8 +11,8 @@ wazuh_sources_installation: user_no_stop: "y" user_install_type: "server" user_dir: "/var/ossec" - user_delete_dir: "y" - user_enable_active_response: "y" + user_delete_dir: null + user_enable_active_response: null user_enable_syscheck: "y" user_enable_rootcheck: "y" user_enable_openscap: "y" From 95ee10d7a71da6e6dfa65d9973069b500a119577 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 19 Nov 2019 12:10:32 +0100 Subject: [PATCH 13/89] Add import of "installation_from_sources" for Debian and RHEL families --- roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml | 4 ++++ roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index fc3a646f..4aa7b045 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -1,4 +1,8 @@ --- +- include_tasks: "installation_from_sources" + when: + - wazuh_sources_installation.enabled + - name: Debian/Ubuntu | Install apt-transport-https and ca-certificates apt: name: diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 2a76fb45..ae7be9d9 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,4 +1,8 @@ --- +- include_tasks: "../roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml" + when: + - wazuh_sources_installation.enabled + - name: RedHat/CentOS | Install Nodejs repo yum_repository: name: NodeJS From d3d0edc291a5c1f13a3ee2f85bf6e3d5b17d39a6 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 19 Nov 2019 12:12:03 +0100 Subject: [PATCH 14/89] Add tasks to install from sources to Wazuh Manager --- .../tasks/installation_from_sources.yml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml new file mode 100644 index 00000000..85920f40 --- /dev/null +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -0,0 +1,70 @@ +--- + +# Wazuh Manager + - name: Install dependencies to build Wazuh packages + package: + name: + - make + - gcc + - automake + - autoconf + - libtool + state: present + + - name: Installing policycoreutils-python (RedHat families) + package: + name: + - policycoreutils-python + when: + - ansible_os_family|lower == "redhat" + + - name: Installing policycoreutils-python-utils (Debian families) + package: + name: + - libc6-dev + - curl + - policycoreutils + when: + - ansible_os_family|lower == "debian" + + - name: Download required packages from github.com/wazuh/wazuh + get_url: + url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_sources_installation.branch }}.tar.gz" + dest: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" + delegate_to: "{{ inventory_hostname }}" + + - name: Extract downloaded Wazuh branch from Github + unarchive: + src: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" + dest: "/tmp/" + remote_src: yes + + - name: Clean remaining files from others builds + command: "make -C src {{ item }}" + args: + chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/src/" + with_items: + - "clean" + - "clean-deps" + register: clean_result + changed_when: clean_result.rc == 0 + failed_when: false + + - name: Render the "preloaded-vars.conf" file + template: + src: "templates/preloaded_vars.conf.j2" + dest: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/etc/preloaded-vars.conf" + owner: root + group: root + mode: '644' + + - name: Executing "install.sh" script to build and install the Wazuh Manager + shell: ./install.sh > /tmp/build_log.txt + register: installation_result + changed_when: installation_result == 0 + args: + chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" + +# Wazuh API + + - name: \ No newline at end of file From cc9f28719cf035bbdce83b838a79d1db6cd99da3 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 19 Nov 2019 12:12:11 +0100 Subject: [PATCH 15/89] Fix linting --- roles/wazuh/ansible-wazuh-manager/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index 901ec050..f2fc55db 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -354,11 +354,11 @@ - ansible_distribution in ['CentOS', 'RedHat', 'Amazon'] and ansible_distribution_major_version|int < 6 - include_tasks: "RMRedHat.yml" - when: + when: - ansible_os_family == "RedHat" or ansible_os_family == "Amazon" - not wazuh_sources_installation.enabled - include_tasks: "RMDebian.yml" - when: + when: - ansible_os_family == "Debian" - not wazuh_sources_installation.enabled From 9e4544ae424ae300165ee0496234234deca8b2e2 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 19 Nov 2019 12:12:36 +0100 Subject: [PATCH 16/89] Add template to configure "preloaded_vars" in Wazuh Manager role --- .../ansible-wazuh-manager/templates/preloaded_vars.conf.j2 | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 diff --git a/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 b/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 new file mode 100644 index 00000000..f02252d1 --- /dev/null +++ b/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 @@ -0,0 +1,7 @@ +{% for key, value in wazuh_sources_installation.items() %} +{% if "user_" in key %} +{% if value is defined and value is not none %} +{{ key|upper }}="{{ value }}" +{% endif %} +{% endif %} +{% endfor %} \ No newline at end of file From a90b241fb0652638e59c205cba07b62f48db820d Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 19 Nov 2019 12:19:32 +0100 Subject: [PATCH 17/89] Remove deprecated API installation tasks --- .../ansible-wazuh-manager/tasks/RedHat.yml | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index c8e8a95a..0f4cf567 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,34 +1,11 @@ --- -- name: RedHat/CentOS | Install Nodejs repo - yum_repository: - name: NodeJS - description: NodeJS-$releasever - baseurl: https://rpm.nodesource.com/pub_6.x/el/{{ ansible_distribution_major_version }}/x86_64 - gpgkey: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL - gpgcheck: true - changed_when: false - when: - - ansible_distribution_major_version|int > 5 - -- name: Fedora | Install Nodejs repo - yum_repository: - name: NodeJS - description: NodeJS-$releasever - baseurl: https://rpm.nodesource.com/pub_6.x/fc/$releasever/x86_64 - gpgkey: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL - gpgcheck: true - when: ansible_distribution == 'Fedora' - -- name: AmazonLinux | Get Nodejs +- name: Install Wazuh API repository shell: | set -o pipefail curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - args: warn: false executable: /bin/bash - creates: /etc/yum.repos.d/nodesource-el7.repo - when: - - ansible_distribution|lower == "amazon" - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: From 219b35c2ef4a97bda98f3aca68857e8b72669045 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 14:58:44 +0100 Subject: [PATCH 18/89] Add API installation tasks to installation_from_sources.yml --- .../tasks/installation_from_sources.yml | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 85920f40..cb12739e 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -1,5 +1,4 @@ --- - # Wazuh Manager - name: Install dependencies to build Wazuh packages package: @@ -9,6 +8,7 @@ - automake - autoconf - libtool + - tar state: present - name: Installing policycoreutils-python (RedHat families) @@ -33,11 +33,15 @@ dest: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" delegate_to: "{{ inventory_hostname }}" + - name: Create folder to extract Wazuh branch + file: + path: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" + state: directory + - name: Extract downloaded Wazuh branch from Github - unarchive: - src: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" - dest: "/tmp/" - remote_src: yes + shell: "tar -xzvf /tmp/{{ wazuh_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_sources_installation.branch }}" + args: + warn: false - name: Clean remaining files from others builds command: "make -C src {{ item }}" @@ -67,4 +71,28 @@ # Wazuh API - - name: \ No newline at end of file + - name: Download script to install Nodejs repository + get_url: + url: "{{ node_js_repository_url }}" + dest: "/tmp/setup_nodejs_repo.sh" + mode: "0700" + + - name: Execute downloaded script to install Nodejs repo + shell: /tmp/setup_nodejs_repo.sh + + - name: Install Nodejs + package: + name: nodejs + state: present + + - name: Run NPM under root account + shell: npm config set user 0 + + - name: Download the installation script to install Wazuh API + get_url: + url: "https://raw.githubusercontent.com/wazuh/wazuh-api/v{{ wazuh_manager_version[:-2] }}/install_api.sh" + dest: "/tmp/install_api.sh" + mode: "0700" + + - name: Execute Wazuh API installation script + shell: /tmp/install_api.sh download From 35d35b5059cecb430b8f60bc01122dabc4f05829 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 14:59:38 +0100 Subject: [PATCH 19/89] Update tasks that download the Wazuh branch and extract it. --- .../tasks/installation_from_sources.yml | 123 +++++++++--------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index d45c4219..7b259b98 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -1,68 +1,69 @@ ---- - - hosts: all - tasks: - - include_vars: ../defaults/main.yml - - name: Install dependencies to build Wazuh packages - package: - name: - - make - - gcc - - automake - - autoconf - - libtool - state: present +--- + - name: Install dependencies to build Wazuh packages + package: + name: + - make + - gcc + - automake + - autoconf + - libtool + - tar + state: present - - name: Installing policycoreutils-python (RedHat families) - package: - name: - - policycoreutils-python - when: - - ansible_os_family|lower == "redhat" + - name: Installing policycoreutils-python (RedHat families) + package: + name: + - policycoreutils-python + when: + - ansible_os_family|lower == "redhat" - - name: Installing policycoreutils-python-utils (Debian families) - package: - name: - - libc6-dev - - curl - - policycoreutils - when: - - ansible_os_family|lower == "debian" + - name: Installing policycoreutils-python-utils (Debian families) + package: + name: + - libc6-dev + - curl + - policycoreutils + when: + - ansible_os_family|lower == "debian" - - name: Download required packages from github.com/wazuh/wazuh - get_url: - url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_sources_installation.branch }}.tar.gz" - dest: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" - delegate_to: "{{ inventory_hostname }}" + - name: Download required packages from github.com/wazuh/wazuh + get_url: + url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_sources_installation.branch }}.tar.gz" + dest: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" + delegate_to: "{{ inventory_hostname }}" - - name: Extract downloaded Wazuh branch from Github - unarchive: - src: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" - dest: "/tmp/" - remote_src: yes + - name: Create folder to extract Wazuh branch + file: + path: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" + state: directory - - name: Clean remaining files from others builds - command: "make -C src {{ item }}" - args: - chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/src/" - with_items: - - "clean" - - "clean-deps" - register: clean_result - changed_when: clean_result.rc == 0 - failed_when: false + - name: Extract downloaded Wazuh branch from Github + shell: "tar -xzvf /tmp/{{ wazuh_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_sources_installation.branch }}" + args: + warn: false - - name: Render the "preloaded-vars.conf" file - template: - src: /templates/preloaded_vars.conf.j2 - dest: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/etc/preloaded-vars.conf" - owner: root - group: root - mode: '644' + - name: Clean remaining files from others builds + command: "make -C src {{ item }}" + args: + chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/src/" + with_items: + - "clean" + - "clean-deps" + register: clean_result + changed_when: clean_result.rc == 0 + failed_when: false - - name: Executing "install.sh" script to build and install the Wazuh Manager - shell: ./install.sh > /tmp/build_log.txt - register: installation_result - changed_when: installation_result == 0 - args: - chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" - become: yes \ No newline at end of file + - name: Render the "preloaded-vars.conf" file + template: + src: "templates/preloaded_vars.conf.j2" + dest: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/etc/preloaded-vars.conf" + owner: root + group: root + mode: '644' + + - name: Executing "install.sh" script to build and install the Wazuh Manager + shell: ./install.sh > /tmp/build_log.txt + register: installation_result + changed_when: installation_result == 0 + args: + chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" \ No newline at end of file From 9b6fd47e3a0b08212ee14dcd0acfea060a01808d Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 15:00:50 +0100 Subject: [PATCH 20/89] Add conditional to don't install Node repo when installing from sources --- roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index 4aa7b045..6e488cc5 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -58,12 +58,14 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Installing NodeJS repository key apt_key: url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Add NodeSource repositories for Node.js apt_repository: @@ -71,6 +73,8 @@ state: present update_cache: true changed_when: false + when: + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Set Distribution CIS filename for Debian/Ubuntu set_fact: From d9cb1a24dd72aa7b576ceb42450a6397324b0181 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 15:02:18 +0100 Subject: [PATCH 21/89] Implement "node_js_repository_url" variable --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index ab652cc2..2e82056c 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -351,3 +351,5 @@ wazuh_agent_configs: format: 'eventchannel' - location: 'System' format: 'eventlog' + +node_js_repository_url: https://rpm.nodesource.com/setup_8.x \ No newline at end of file From 2c9b18de72be4986affbffd96803b1aae4e66ac7 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 16:36:56 +0100 Subject: [PATCH 22/89] Update ("user_update" and "branch") variables. --- roles/wazuh/ansible-wazuh-agent/defaults/main.yml | 4 ++-- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index 886de1bb..e7126e0a 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -2,7 +2,7 @@ wazuh_agent_version: 3.10.2-1 wazuh_sources_installation: enabled: "true" - branch: "3.10" + branch: "v3.10.2" user_language: "y" user_no_stop: "y" user_install_type: "agent" @@ -15,7 +15,7 @@ wazuh_sources_installation: user_enable_sca: "y" user_enable_authd: "y" user_generate_authd_cert: "n" - user_update: null + user_update: "y" user_binaryinstall: null user_agent_server_ip: "172.16.1.2" user_agent_server_name: null diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 2e82056c..68948ae4 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -6,7 +6,7 @@ wazuh_manager_package_state: present wazuh_sources_installation: enabled: true - branch: "3.10" + branch: "v3.10.2" user_language: "en" user_no_stop: "y" user_install_type: "server" @@ -18,7 +18,7 @@ wazuh_sources_installation: user_enable_openscap: "y" user_enable_authd: "y" user_generate_authd_cert: null - user_update: null + user_update: "y" user_binaryinstall: null user_enable_email: "n" user_auto_start: "y" From 0329441817c2c8604f337700d157c77d35c3f6a4 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 16:37:27 +0100 Subject: [PATCH 23/89] Update tasks and conditioinals for Agent installations in Debian families --- roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml index 5e2cfae6..87112798 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml @@ -1,6 +1,6 @@ --- -- include_tasks: "installation_from_sources" +- include_tasks: "../roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml" when: - wazuh_sources_installation.enabled @@ -25,6 +25,7 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Installing Wazuh repository key apt_key: From a6d614610e53d86e6cc9a451493b3847694891fc Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 16:37:49 +0100 Subject: [PATCH 24/89] Format updates for "installation_from_sources.yml" --- .../ansible-wazuh-agent/tasks/installation_from_sources.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index 7b259b98..053b4ea6 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -1,4 +1,5 @@ ---- +--- + - name: Install dependencies to build Wazuh packages package: name: @@ -61,7 +62,7 @@ group: root mode: '644' - - name: Executing "install.sh" script to build and install the Wazuh Manager + - name: Executing "install.sh" script to build and install the Wazuh Agent shell: ./install.sh > /tmp/build_log.txt register: installation_result changed_when: installation_result == 0 From c5f2893a0b6bb81a74eb4c14d320e50b826656ea Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 16:38:02 +0100 Subject: [PATCH 25/89] Update tasks path in "Redhat.yml" --- roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml index a81ecea5..36984115 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml @@ -1,6 +1,6 @@ --- -- include_tasks: "installation_from_sources" +- include_tasks: "../roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml" when: - wazuh_sources_installation.enabled From 841fe3d28d559ee47cf4f93f23cea0e4d6aa44ca Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 16:39:57 +0100 Subject: [PATCH 26/89] Remove testing address in "user_agent_server_ip" --- roles/wazuh/ansible-wazuh-agent/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index e7126e0a..b4bed923 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -17,7 +17,7 @@ wazuh_sources_installation: user_generate_authd_cert: "n" user_update: "y" user_binaryinstall: null - user_agent_server_ip: "172.16.1.2" + user_agent_server_ip: "YOUR_MANAGER_IP" user_agent_server_name: null user_agent_config_profile: null user_ca_store: "/var/ossec/wpk_root.pem" From e0038118e1ffb2a02ee39d733cff0c26138e5afe Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 16:49:11 +0100 Subject: [PATCH 27/89] Restore "creates" setting in Wazuh Kibana plugin installation --- roles/elastic-stack/ansible-kibana/tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/elastic-stack/ansible-kibana/tasks/main.yml b/roles/elastic-stack/ansible-kibana/tasks/main.yml index efde790c..622db80b 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/main.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/main.yml @@ -103,6 +103,7 @@ NODE_OPTIONS: "--max-old-space-size=3072" args: executable: /bin/bash + creates: /usr/share/kibana/plugins/wazuh/package.json become: yes become_user: kibana notify: restart kibana From 571abfbb2c7d7152df44574db890e23e4a208dea Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 19:00:53 +0100 Subject: [PATCH 28/89] Update untar task to pass linting, added comment --- .../tasks/installation_from_sources.yml | 7 ++++--- .../tasks/installation_from_sources.yml | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index 053b4ea6..381f9c67 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -1,5 +1,4 @@ --- - - name: Install dependencies to build Wazuh packages package: name: @@ -38,8 +37,10 @@ path: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" state: directory - - name: Extract downloaded Wazuh branch from Github - shell: "tar -xzvf /tmp/{{ wazuh_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_sources_installation.branch }}" + - name: Extract downloaded Wazuh branch from Github # Using shell instead of unarchive due to that module not working properlyh with --strip + command: "tar -xzvf /tmp/{{ wazuh_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_sources_installation.branch }}" + register: wazuh_untar + changed_when: wazuh_untar.rc ==0 args: warn: false diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index cb12739e..65e06e24 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -38,8 +38,10 @@ path: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" state: directory - - name: Extract downloaded Wazuh branch from Github - shell: "tar -xzvf /tmp/{{ wazuh_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_sources_installation.branch }}" + - name: Extract downloaded Wazuh branch from Github # Using shell instead of unarchive due to that module not working properlyh with --strip + command: "tar -xzvf /tmp/{{ wazuh_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_sources_installation.branch }}" + register: wazuh_untar + changed_when: wazuh_untar.rc ==0 args: warn: false From 9d62860ea1644656db5c949e2c46f152f87e83c1 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 19:06:48 +0100 Subject: [PATCH 29/89] Update "installation_from_sources" to fix linting errors --- .../tasks/installation_from_sources.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 65e06e24..1ecfd7c8 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -80,15 +80,19 @@ mode: "0700" - name: Execute downloaded script to install Nodejs repo - shell: /tmp/setup_nodejs_repo.sh - + command: /tmp/setup_nodejs_repo.sh + register: node_repo_installation_result + changed_when: node_repo_installation_result.rc == 0 + - name: Install Nodejs package: name: nodejs state: present - + - name: Run NPM under root account - shell: npm config set user 0 + command: npm config set user 0 + register: allow_root_npm + changed_when: allow_root_npm.rc == 0 - name: Download the installation script to install Wazuh API get_url: @@ -97,4 +101,6 @@ mode: "0700" - name: Execute Wazuh API installation script - shell: /tmp/install_api.sh download + command: /tmp/install_api.sh download + register: install_api + changed_when: install_api.rc == 0 From e3ecb74ca87f7f4e561da8fe7e19a96677220b3d Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 19:09:40 +0100 Subject: [PATCH 30/89] Move "installation_from_sources" include to Linux.yml --- roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml | 7 +------ roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml | 4 ++++ roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml | 5 ----- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml index 87112798..81062d80 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml @@ -1,9 +1,4 @@ --- - -- include_tasks: "../roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml" - when: - - wazuh_sources_installation.enabled - - name: Debian/Ubuntu | Install apt-transport-https and ca-certificates apt: name: @@ -25,7 +20,7 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - - not wazuh_sources_installation.enabled + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Installing Wazuh repository key apt_key: diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml index 5cd95ff4..0c1f8e5f 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml @@ -1,4 +1,8 @@ --- +- include_tasks: "../roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml" + when: + - wazuh_sources_installation.enabled + - include_tasks: "RedHat.yml" when: ansible_os_family == "RedHat" diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml index 36984115..13b1b3e8 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml @@ -1,9 +1,4 @@ --- - -- include_tasks: "../roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml" - when: - - wazuh_sources_installation.enabled - - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: name: wazuh_repo From c64d331e7f99a8cac94058f778a7320479aeeac6 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 19:16:44 +0100 Subject: [PATCH 31/89] Fix include_tasks for "installation_from_sources.yml" --- roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml | 2 +- roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml | 8 ++++---- roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml index 0c1f8e5f..e258fa1f 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml @@ -1,5 +1,5 @@ --- -- include_tasks: "../roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml" +- include_tasks: "../tasks/installation_from_sources.yml" when: - wazuh_sources_installation.enabled diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index 6e488cc5..3bd2c541 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -1,5 +1,5 @@ --- -- include_tasks: "installation_from_sources" +- include_tasks: "installation_from_sources.yml" when: - wazuh_sources_installation.enabled @@ -58,14 +58,14 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - - not wazuh_sources_installation.enabled + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Installing NodeJS repository key apt_key: url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) - - not wazuh_sources_installation.enabled + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Add NodeSource repositories for Node.js apt_repository: @@ -74,7 +74,7 @@ update_cache: true changed_when: false when: - - not wazuh_sources_installation.enabled + - not wazuh_sources_installation.enabled - name: Debian/Ubuntu | Set Distribution CIS filename for Debian/Ubuntu set_fact: diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index ae7be9d9..ed681344 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,5 +1,5 @@ --- -- include_tasks: "../roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml" +- include_tasks: "../tasks/installation_from_sources.yml" when: - wazuh_sources_installation.enabled From 320b3732404cced74dceed93f0d57e4d1e835610 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 13:28:46 +0100 Subject: [PATCH 32/89] Add default variables to build Wazuh Kibana Plugin --- roles/elastic-stack/ansible-kibana/defaults/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/roles/elastic-stack/ansible-kibana/defaults/main.yml b/roles/elastic-stack/ansible-kibana/defaults/main.yml index 526bfabf..f6ac7023 100644 --- a/roles/elastic-stack/ansible-kibana/defaults/main.yml +++ b/roles/elastic-stack/ansible-kibana/defaults/main.yml @@ -23,3 +23,10 @@ node_certs_destination: /etc/kibana/certs master_certs_path: /es_certs generate_CA: true ca_cert_name: "" + +# Nodejs +node_js_repository_url: https://rpm.nodesource.com/setup_8.x + +# Build from sources +build_from_sources: true +wazuh_plugin_branch: 3.10-7.4 \ No newline at end of file From 2f8da1b7c508f88c13dcf1ccc9760dd9c90a6fd3 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 13:29:03 +0100 Subject: [PATCH 33/89] Add "build_wazuh_plugin.yml" tasks --- .../tasks/build_wazuh_plugin.yml | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml diff --git a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml new file mode 100644 index 00000000..494bc8f0 --- /dev/null +++ b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml @@ -0,0 +1,76 @@ +--- + + - name: Ensure the Git package is present + package: + name: git + state: present + + - name: Download script to install Nodejs repository + get_url: + url: "{{ node_js_repository_url }}" + dest: "/tmp/setup_nodejs_repo.sh" + mode: "0700" + + - name: Execute downloaded script to install Nodejs repo + command: /tmp/setup_nodejs_repo.sh + register: node_repo_installation_result + changed_when: node_repo_installation_result.rc == 0 + + - name: Install Nodejs + package: + name: nodejs + state: present + + - name: Run NPM under root account + command: npm config set user 0 + register: allow_root_npm + changed_when: allow_root_npm.rc == 0 + + - name: Install yarn dependency to build the Wazuh Kibana Plugin + command: npm install -g yarn@1.10.1 + register: install_yarn_result + changed_when: install_yarn_result == 0 + + - name: Remove old wazuh-kibana-app git directory + file: + path: /tmp/app + state: absent + + - name: Clone wazuh-kibana-app repository # Using command as git module doesn't cover single-branch nor depth + command: git clone https://github.com/wazuh/wazuh-kibana-app -b {{ wazuh_plugin_branch }} --single-branch --depth=1 app # noqa 303 + register: clone_app_repo_result + changed_when: clone_app_repo_result.rc == 0 + args: + chdir: "/tmp" + + - name: Executing yarn to build the package + command: "{{ item }}" + with_items: + - "yarn" + - "yarn build" + - "yarn build" # Executing multiple times to workaround errors returned by yarn build + register: yarn_execution_result + changed_when: yarn_execution_result == 0 + args: + chdir: "/tmp/app/" + + - name: Obtain name of generated package + shell: "find ./ -name 'wazuh-*.zip' -printf '%f\\n'" + register: wazuhapp_package_name + changed_when: false + args: + chdir: "/tmp/app/build" + + - name: Install Wazuh Plugin (can take a while) + shell: "/usr/share/kibana/bin/kibana-plugin install file:///tmp/app/build/{{ wazuhapp_package_name.stdout }}" + environment: + NODE_OPTIONS: "--max-old-space-size=3072" + args: + executable: /bin/bash + creates: /usr/share/kibana/plugins/wazuh/package.json + become: yes + become_user: kibana + notify: restart kibana + tags: + - install + - skip_ansible_lint From 886e96b182c90bbbd3e994d59246a39e8a058894 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 13:29:58 +0100 Subject: [PATCH 34/89] Update "main.yml" in Kibana installation to enable sources install --- .../ansible-kibana/tasks/main.yml | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/roles/elastic-stack/ansible-kibana/tasks/main.yml b/roles/elastic-stack/ansible-kibana/tasks/main.yml index 622db80b..89af291c 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/main.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/main.yml @@ -82,8 +82,8 @@ register: wazuh_app_verify changed_when: false failed_when: - - wazuh_app_verify.rc != 0 - - wazuh_app_verify.rc != 1 + - wazuh_app_verify.rc != 0 + - wazuh_app_verify.rc != 1 - name: Removing old Wazuh-APP command: /usr/share/kibana/bin/kibana-plugin --allow-root remove wazuh @@ -91,13 +91,24 @@ tags: install - name: Removing bundles - file: path=/usr/share/kibana/optimize/bundles state=absent - become: yes - become_user: kibana + file: + path: /usr/share/kibana/optimize/bundles + state: absent when: wazuh_app_verify.rc == 1 tags: install -- name: Install Wazuh-APP (can take a while) +- name: Explicitly starting Kibana to generate "wazuh-" + service: + name: kibana + state: started + +- name: Build and Install Wazuh Kibana Plugin from sources + import_tasks: build_wazuh_plugin.yml + when: + - build_from_sources is defined + - build_from_sources + +- name: Install Wazuh Plugin (can take a while) shell: "/usr/share/kibana/bin/kibana-plugin install {{ wazuh_app_url }}-{{ wazuh_version }}_{{ elastic_stack_version }}.zip" environment: NODE_OPTIONS: "--max-old-space-size=3072" @@ -110,6 +121,8 @@ tags: - install - skip_ansible_lint + when: + - not build_from_sources - name: Reload systemd configuration systemd: From 3acdd20dff1b4c2eb4ffb7c953ebbafaa58611b9 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 13:30:43 +0100 Subject: [PATCH 35/89] Change Wazuh API build task to log info to "/tmp/build_wazuh_api_log." --- .../ansible-wazuh-manager/tasks/installation_from_sources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 1ecfd7c8..472eab8f 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -101,6 +101,6 @@ mode: "0700" - name: Execute Wazuh API installation script - command: /tmp/install_api.sh download + shell: /tmp/install_api.sh download > /tmp/build_api_log.txt register: install_api changed_when: install_api.rc == 0 From 13b232154026a852998b499ad8757a906bf9a538 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 15:01:15 +0100 Subject: [PATCH 36/89] Rename wazuh_sources_installation to wazuh_manager sources_installation --- playbooks/wazuh-elastic_stack-single.yml | 12 +-- .../ansible-wazuh-agent/defaults/main.yml | 2 +- .../ansible-wazuh-agent/tasks/Debian.yml | 4 +- .../wazuh/ansible-wazuh-agent/tasks/Linux.yml | 10 +-- .../ansible-wazuh-agent/tasks/RedHat.yml | 4 +- .../tasks/installation_from_sources.yml | 14 ++-- .../templates/preloaded_vars.conf.j2 | 2 +- .../ansible-wazuh-manager/defaults/main.yml | 2 +- .../ansible-wazuh-manager/tasks/Debian.yml | 16 ++-- .../ansible-wazuh-manager/tasks/RedHat.yml | 8 +- .../tasks/installation_from_sources.yml | 74 ++++++++++--------- .../ansible-wazuh-manager/tasks/main.yml | 4 +- .../templates/preloaded_vars.conf.j2 | 2 +- 13 files changed, 81 insertions(+), 73 deletions(-) diff --git a/playbooks/wazuh-elastic_stack-single.yml b/playbooks/wazuh-elastic_stack-single.yml index 051b5fd2..bc353dfd 100644 --- a/playbooks/wazuh-elastic_stack-single.yml +++ b/playbooks/wazuh-elastic_stack-single.yml @@ -1,8 +1,8 @@ --- -- hosts: +- hosts: all roles: - - {role: ../roles/wazuh/ansible-wazuh-manager} - - role: ../roles/wazuh/ansible-filebeat - filebeat_output_elasticsearch_hosts: localhost:9200 - - {role: ../roles/elastic-stack/ansible-elasticsearch, elasticsearch_network_host: '0.0.0.0', single_node: true} - - { role: ../roles/elastic-stack/ansible-kibana, elasticsearch_network_host: 'localhost' } + # - {role: ../roles/wazuh/ansible-wazuh-manager} + # - role: ../roles/wazuh/ansible-filebeat + # filebeat_output_elasticsearch_hosts: 172.24.1.2:9200 + # - {role: ../roles/elastic-stack/ansible-elasticsearch, elasticsearch_network_host: '0.0.0.0', single_node: true} + - { role: ../roles/elastic-stack/ansible-kibana, elasticsearch_network_host: '172.24.1.1', elasticsearch_reachable_host: '172.24.1.2' } diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index b4bed923..3ff7d803 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -1,6 +1,6 @@ --- wazuh_agent_version: 3.10.2-1 -wazuh_sources_installation: +wazuh_manager_sources_installation: enabled: "true" branch: "v3.10.2" user_language: "y" diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml index 81062d80..329fab6d 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml @@ -20,7 +20,7 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Installing Wazuh repository key apt_key: @@ -35,7 +35,7 @@ state: present update_cache: true when: - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Set Distribution CIS filename for debian set_fact: diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml index e258fa1f..9c8db0b8 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml @@ -1,7 +1,7 @@ --- - include_tasks: "../tasks/installation_from_sources.yml" when: - - wazuh_sources_installation.enabled + - wazuh_manager_sources_installation.enabled - include_tasks: "RedHat.yml" when: ansible_os_family == "RedHat" @@ -17,7 +17,7 @@ poll: 30 when: - ansible_os_family|lower == "redhat" - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled tags: - init @@ -28,7 +28,7 @@ cache_valid_time: 3600 when: - ansible_os_family|lower != "redhat" - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled tags: - init @@ -200,9 +200,9 @@ - include_tasks: "RMRedHat.yml" when: - ansible_os_family == "RedHat" - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - include_tasks: "RMDebian.yml" when: - ansible_os_family == "Debian" - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml index 13b1b3e8..e9580a94 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml @@ -10,7 +10,7 @@ when: - (ansible_facts['os_family']|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled register: repo_v5_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo @@ -23,7 +23,7 @@ changed_when: false when: - repo_v5_installed is skipped - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: RedHat/CentOS/Fedora | download Oracle Java RPM get_url: diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index 381f9c67..55714673 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -28,17 +28,17 @@ - name: Download required packages from github.com/wazuh/wazuh get_url: - url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_sources_installation.branch }}.tar.gz" - dest: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" + url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_manager_sources_installation.branch }}.tar.gz" + dest: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" delegate_to: "{{ inventory_hostname }}" - name: Create folder to extract Wazuh branch file: - path: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" + path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" state: directory - name: Extract downloaded Wazuh branch from Github # Using shell instead of unarchive due to that module not working properlyh with --strip - command: "tar -xzvf /tmp/{{ wazuh_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_sources_installation.branch }}" + command: "tar -xzvf /tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" register: wazuh_untar changed_when: wazuh_untar.rc ==0 args: @@ -47,7 +47,7 @@ - name: Clean remaining files from others builds command: "make -C src {{ item }}" args: - chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/src/" + chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/src/" with_items: - "clean" - "clean-deps" @@ -58,7 +58,7 @@ - name: Render the "preloaded-vars.conf" file template: src: "templates/preloaded_vars.conf.j2" - dest: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/etc/preloaded-vars.conf" + dest: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/etc/preloaded-vars.conf" owner: root group: root mode: '644' @@ -68,4 +68,4 @@ register: installation_result changed_when: installation_result == 0 args: - chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" \ No newline at end of file + chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 b/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 index f02252d1..be552560 100644 --- a/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 +++ b/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 @@ -1,4 +1,4 @@ -{% for key, value in wazuh_sources_installation.items() %} +{% for key, value in wazuh_manager_sources_installation.items() %} {% if "user_" in key %} {% if value is defined and value is not none %} {{ key|upper }}="{{ value }}" diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 68948ae4..2767ab37 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -4,7 +4,7 @@ wazuh_manager_version: 3.10.2-1 wazuh_manager_fqdn: "wazuh-server" wazuh_manager_package_state: present -wazuh_sources_installation: +wazuh_manager_sources_installation: enabled: true branch: "v3.10.2" user_language: "en" diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index 3bd2c541..c8b52fda 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -1,7 +1,7 @@ --- - include_tasks: "installation_from_sources.yml" when: - - wazuh_sources_installation.enabled + - wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Install apt-transport-https and ca-certificates apt: @@ -27,14 +27,14 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Installing Wazuh repository key apt_key: url: "{{ wazuh_manager_config.repo.gpg }}" when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Add Wazuh repositories apt_repository: @@ -44,7 +44,7 @@ update_cache: true changed_when: false when: - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Installing NodeJS repository key (Ubuntu 14) become: true @@ -58,14 +58,14 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Installing NodeJS repository key apt_key: url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Add NodeSource repositories for Node.js apt_repository: @@ -74,7 +74,7 @@ update_cache: true changed_when: false when: - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: Debian/Ubuntu | Set Distribution CIS filename for Debian/Ubuntu set_fact: @@ -139,4 +139,4 @@ until: wazuh_manager_main_packages_installed is succeeded tags: init when: - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index ed681344..9baae413 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,7 +1,7 @@ --- - include_tasks: "../tasks/installation_from_sources.yml" when: - - wazuh_sources_installation.enabled + - wazuh_manager_sources_installation.enabled - name: RedHat/CentOS | Install Nodejs repo yum_repository: @@ -45,7 +45,7 @@ when: - (ansible_os_family|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled register: repo_v5_manager_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo @@ -58,7 +58,7 @@ changed_when: false when: - repo_v5_manager_installed is skipped - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - name: RedHat/CentOS/Fedora | Install openscap package: name={{ item }} state=present @@ -155,7 +155,7 @@ until: wazuh_manager_main_packages_installed is succeeded when: - ansible_os_family|lower == "redhat" - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled tags: - init diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 472eab8f..8469713e 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -29,17 +29,17 @@ - name: Download required packages from github.com/wazuh/wazuh get_url: - url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_sources_installation.branch }}.tar.gz" - dest: "/tmp/{{ wazuh_sources_installation.branch }}.tar.gz" + url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_manager_sources_installation.branch }}.tar.gz" + dest: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" delegate_to: "{{ inventory_hostname }}" - name: Create folder to extract Wazuh branch file: - path: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" + path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" state: directory - name: Extract downloaded Wazuh branch from Github # Using shell instead of unarchive due to that module not working properlyh with --strip - command: "tar -xzvf /tmp/{{ wazuh_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_sources_installation.branch }}" + command: "tar -xzvf /tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" register: wazuh_untar changed_when: wazuh_untar.rc ==0 args: @@ -48,7 +48,7 @@ - name: Clean remaining files from others builds command: "make -C src {{ item }}" args: - chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/src/" + chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/src/" with_items: - "clean" - "clean-deps" @@ -59,7 +59,7 @@ - name: Render the "preloaded-vars.conf" file template: src: "templates/preloaded_vars.conf.j2" - dest: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}/etc/preloaded-vars.conf" + dest: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/etc/preloaded-vars.conf" owner: root group: root mode: '644' @@ -69,38 +69,46 @@ register: installation_result changed_when: installation_result == 0 args: - chdir: "/tmp/wazuh-{{ wazuh_sources_installation.branch }}" + chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" # Wazuh API + - name: Check if Wazuh API is already installed + stat: + path: /var/ossec/api/app.js + register: wazuh_api - - name: Download script to install Nodejs repository - get_url: - url: "{{ node_js_repository_url }}" - dest: "/tmp/setup_nodejs_repo.sh" - mode: "0700" + - name: Install Wazuh API from sources + block: + - name: Download script to install Nodejs repository + get_url: + url: "{{ node_js_repository_url }}" + dest: "/tmp/setup_nodejs_repo.sh" + mode: "0700" - - name: Execute downloaded script to install Nodejs repo - command: /tmp/setup_nodejs_repo.sh - register: node_repo_installation_result - changed_when: node_repo_installation_result.rc == 0 + - name: Execute downloaded script to install Nodejs repo + command: /tmp/setup_nodejs_repo.sh + register: node_repo_installation_result + changed_when: node_repo_installation_result.rc == 0 - - name: Install Nodejs - package: - name: nodejs - state: present + - name: Install Nodejs + package: + name: nodejs + state: present - - name: Run NPM under root account - command: npm config set user 0 - register: allow_root_npm - changed_when: allow_root_npm.rc == 0 + - name: Run NPM under root account + command: npm config set user 0 + register: allow_root_npm + changed_when: allow_root_npm.rc == 0 - - name: Download the installation script to install Wazuh API - get_url: - url: "https://raw.githubusercontent.com/wazuh/wazuh-api/v{{ wazuh_manager_version[:-2] }}/install_api.sh" - dest: "/tmp/install_api.sh" - mode: "0700" + - name: Download the installation script to install Wazuh API + get_url: + url: "https://raw.githubusercontent.com/wazuh/wazuh-api/v{{ wazuh_manager_version[:-2] }}/install_api.sh" + dest: "/tmp/install_api.sh" + mode: "0700" - - name: Execute Wazuh API installation script - shell: /tmp/install_api.sh download > /tmp/build_api_log.txt - register: install_api - changed_when: install_api.rc == 0 + - name: Execute Wazuh API installation script + shell: /tmp/install_api.sh download > /tmp/build_api_log.txt + register: install_api + changed_when: install_api.rc == 0 + when: + - not wazuh_api.stat.exists diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index f2fc55db..d2c99535 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -356,9 +356,9 @@ - include_tasks: "RMRedHat.yml" when: - ansible_os_family == "RedHat" or ansible_os_family == "Amazon" - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled - include_tasks: "RMDebian.yml" when: - ansible_os_family == "Debian" - - not wazuh_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled diff --git a/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 b/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 index f02252d1..be552560 100644 --- a/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 +++ b/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 @@ -1,4 +1,4 @@ -{% for key, value in wazuh_sources_installation.items() %} +{% for key, value in wazuh_manager_sources_installation.items() %} {% if "user_" in key %} {% if value is defined and value is not none %} {{ key|upper }}="{{ value }}" From 7bf823bcadead3ce3bae0206882d3dd43d2b98c9 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 18:44:34 +0100 Subject: [PATCH 37/89] Split preloaded_vars into preloaded_vars_manager and api --- .../templates/preloaded_vars_api.conf.j2 | 7 +++++++ ...eloaded_vars.conf.j2 => preloaded_vars_manager.conf.j2} | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars_api.conf.j2 rename roles/wazuh/ansible-wazuh-manager/templates/{preloaded_vars.conf.j2 => preloaded_vars_manager.conf.j2} (93%) diff --git a/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars_api.conf.j2 b/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars_api.conf.j2 new file mode 100644 index 00000000..198178c8 --- /dev/null +++ b/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars_api.conf.j2 @@ -0,0 +1,7 @@ +{% for key, value in wazuh_api_sources_installation.items() %} +{% if "enabled" not in key and "branch" not in key %} +{% if value is defined and value is not none %} +{{ key|upper }}="{{ value }}" +{% endif %} +{% endif %} +{% endfor %} \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 b/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars_manager.conf.j2 similarity index 93% rename from roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 rename to roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars_manager.conf.j2 index be552560..3dacef92 100644 --- a/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars.conf.j2 +++ b/roles/wazuh/ansible-wazuh-manager/templates/preloaded_vars_manager.conf.j2 @@ -4,4 +4,4 @@ {{ key|upper }}="{{ value }}" {% endif %} {% endif %} -{% endfor %} \ No newline at end of file +{% endfor %} From 628dcb2ccc8ddcc1a27d5d1255c206a9ae1cc63e Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 18:45:01 +0100 Subject: [PATCH 38/89] Update conditonals and add required tasks to RedHat.yml --- .../ansible-wazuh-manager/tasks/RedHat.yml | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 9baae413..354beca4 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,7 +1,4 @@ --- -- include_tasks: "../tasks/installation_from_sources.yml" - when: - - wazuh_manager_sources_installation.enabled - name: RedHat/CentOS | Install Nodejs repo yum_repository: @@ -13,6 +10,7 @@ changed_when: false when: - ansible_distribution_major_version|int > 5 + - not wazuh_api_sources_installation.enabled - name: Fedora | Install Nodejs repo yum_repository: @@ -21,7 +19,9 @@ baseurl: https://rpm.nodesource.com/pub_6.x/fc/$releasever/x86_64 gpgkey: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL gpgcheck: true - when: ansible_distribution == 'Fedora' + when: + - ansible_distribution == 'Fedora' + - not wazuh_api_sources_installation.enabled - name: AmazonLinux | Get Nodejs shell: | @@ -33,6 +33,7 @@ creates: /etc/yum.repos.d/nodesource-el7.repo when: - ansible_distribution|lower == "amazon" + - not wazuh_api_sources_installation.enabled - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: @@ -46,6 +47,7 @@ - (ansible_os_family|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) - not wazuh_manager_sources_installation.enabled + - not wazuh_api_sources_installation.enabled register: repo_v5_manager_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo @@ -58,7 +60,7 @@ changed_when: false when: - repo_v5_manager_installed is skipped - - not wazuh_manager_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled or not wazuh_api_sources_installation.enabled - name: RedHat/CentOS/Fedora | Install openscap package: name={{ item }} state=present @@ -144,13 +146,10 @@ when: - ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA" -- name: CentOS/RedHat/Amazon | Install wazuh-manager, wazuh-api +- name: CentOS/RedHat/Amazon | Install Wazuh Manager package: - name: "{{ item }}-{{ wazuh_manager_version }}" + name: "wazuh-manager-{{ wazuh_manager_version }}" state: "{{ wazuh_manager_package_state }}" - with_items: - - wazuh-manager - - wazuh-api register: wazuh_manager_main_packages_installed until: wazuh_manager_main_packages_installed is succeeded when: @@ -159,6 +158,28 @@ tags: - init +- include_tasks: "../tasks/installation_from_sources.yml" + tags: manager + when: + - wazuh_manager_sources_installation.enabled + +- name: CentOS/RedHat/Amazon | Install Wazuh API + package: + name: "wazuh-api-{{ wazuh_manager_version }}" + state: "{{ wazuh_manager_package_state }}" + register: wazuh_api_main_packages_installed + until: wazuh_api_main_packages_installed is succeeded + when: + - ansible_os_family|lower == "redhat" + - not wazuh_api_sources_installation.enabled + tags: + - init + +- include_tasks: "../tasks/installation_from_sources.yml" + tags: api + when: + - wazuh_api_sources_installation.enabled + - name: CentOS/RedHat 6 | Enabling python2.7 and sqlite3 replace: path: /etc/init.d/wazuh-manager @@ -181,3 +202,4 @@ - ansible_distribution_major_version|int < 6 tags: - init + From 380d4d14300b71b8f99822cc29253e834cf3a7e7 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 18:45:25 +0100 Subject: [PATCH 39/89] Update installation_from_sources conditionals and blocks --- .../tasks/installation_from_sources.yml | 196 +++++++++++------- 1 file changed, 122 insertions(+), 74 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 8469713e..ef24c238 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -1,75 +1,98 @@ --- # Wazuh Manager - - name: Install dependencies to build Wazuh packages - package: - name: - - make - - gcc - - automake - - autoconf - - libtool - - tar - state: present + - name: Check if Wazuh Manager is already installed + stat: + path: /var/ossec/bin/ossec-control + register: wazuh_ossec_control - - name: Installing policycoreutils-python (RedHat families) - package: - name: - - policycoreutils-python + - name: Installing Wazuh Manager from sources + block: + - name: Install dependencies to build Wazuh packages + package: + name: + - make + - gcc + - automake + - autoconf + - libtool + - tar + state: present + + - name: Installing policycoreutils-python (RedHat families) + package: + name: + - policycoreutils-python + when: + - ansible_os_family|lower == "redhat" + + - name: Installing policycoreutils-python-utils (Debian families) + package: + name: + - libc6-dev + - curl + - policycoreutils + when: + - ansible_os_family|lower == "debian" + + - name: Remove old repository folder + file: + path: /tmp/wazuh-{{ wazuh_manager_sources_installation.branch }} + state: absent + + - name: Download required packages from github.com/wazuh/wazuh + get_url: + url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_manager_sources_installation.branch }}.tar.gz" + dest: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" + delegate_to: "{{ inventory_hostname }}" + + - name: Create folder to extract Wazuh branch + file: + path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" + state: directory + + # When downloading "v3.10.2" extracted folder name is 3.10.2. + # Explicitly creating the folder with proper naming and striping first level in .tar.gz file + + - name: Extract downloaded Wazuh branch from Github # Using shell instead of unarchive due to that module not working properlyh with --strip + command: >- + tar -xzvf /tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz + --strip 1 + --directory /tmp/wazuh-{{ wazuh_manager_sources_installation.branch }} + register: wazuh_untar + changed_when: wazuh_untar.rc ==0 + args: + warn: false + + - name: Clean remaining files from others builds + command: "make -C src {{ item }}" + args: + chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/src/" + with_items: + - "clean" + - "clean-deps" + register: clean_result + changed_when: clean_result.rc == 0 + failed_when: false + + - name: Render the "preloaded-vars.conf" file + template: + src: "templates/preloaded_vars_manager.conf.j2" + dest: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/etc/preloaded-vars.conf" + owner: root + group: root + mode: '644' + + - name: Executing "install.sh" script to build and install the Wazuh Manager + shell: ./install.sh > /tmp/build_manager_log.txt + register: installation_result + changed_when: installation_result == 0 + args: + chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" when: - - ansible_os_family|lower == "redhat" - - - name: Installing policycoreutils-python-utils (Debian families) - package: - name: - - libc6-dev - - curl - - policycoreutils - when: - - ansible_os_family|lower == "debian" - - - name: Download required packages from github.com/wazuh/wazuh - get_url: - url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_manager_sources_installation.branch }}.tar.gz" - dest: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" - delegate_to: "{{ inventory_hostname }}" - - - name: Create folder to extract Wazuh branch - file: - path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" - state: directory - - - name: Extract downloaded Wazuh branch from Github # Using shell instead of unarchive due to that module not working properlyh with --strip - command: "tar -xzvf /tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" - register: wazuh_untar - changed_when: wazuh_untar.rc ==0 - args: - warn: false - - - name: Clean remaining files from others builds - command: "make -C src {{ item }}" - args: - chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/src/" - with_items: - - "clean" - - "clean-deps" - register: clean_result - changed_when: clean_result.rc == 0 - failed_when: false - - - name: Render the "preloaded-vars.conf" file - template: - src: "templates/preloaded_vars.conf.j2" - dest: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/etc/preloaded-vars.conf" - owner: root - group: root - mode: '644' - - - name: Executing "install.sh" script to build and install the Wazuh Manager - shell: ./install.sh > /tmp/build_log.txt - register: installation_result - changed_when: installation_result == 0 - args: - chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" + - not wazuh_ossec_control.stat.exists + - wazuh_manager_sources_installation.enabled + tags: + - manager # Wazuh API - name: Check if Wazuh API is already installed @@ -79,6 +102,11 @@ - name: Install Wazuh API from sources block: + - name: Ensure Git is present in the host + package: + name: git + state: present + - name: Download script to install Nodejs repository get_url: url: "{{ node_js_repository_url }}" @@ -100,15 +128,35 @@ register: allow_root_npm changed_when: allow_root_npm.rc == 0 - - name: Download the installation script to install Wazuh API - get_url: - url: "https://raw.githubusercontent.com/wazuh/wazuh-api/v{{ wazuh_manager_version[:-2] }}/install_api.sh" - dest: "/tmp/install_api.sh" - mode: "0700" + - name: Remove old repository folder + file: + path: /tmp/wazuh-api + state: absent + + - name: Download the Wazuh API repository + git: + repo: 'https://github.com/wazuh/wazuh-api.git' + version: "{{ wazuh_api_sources_installation.branch }}" + dest: /tmp/wazuh-api + + - name: Configure Wazuh API installation + template: + src: "templates/preloaded_vars_api.conf.j2" + dest: "/tmp/wazuh-api/configuration/preloaded_vars.conf" + owner: root + group: root + mode: '644' - name: Execute Wazuh API installation script - shell: /tmp/install_api.sh download > /tmp/build_api_log.txt + shell: ./install_api.sh > /tmp/build_api_log.txt register: install_api changed_when: install_api.rc == 0 + args: + chdir: "/tmp/wazuh-api" + notify: + - restart wazuh-api when: - not wazuh_api.stat.exists + - wazuh_api_sources_installation.enabled + tags: + - api \ No newline at end of file From 9e6966b6994d07ae9ef18f054500b27ff8ea3bf1 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 18:45:45 +0100 Subject: [PATCH 40/89] Fix conditionals for Debian families. Split Manager and API install --- .../ansible-wazuh-manager/tasks/Debian.yml | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index c8b52fda..6da6a6f3 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -1,7 +1,7 @@ --- - include_tasks: "installation_from_sources.yml" when: - - wazuh_manager_sources_installation.enabled + - wazuh_manager_sources_installation.enabled or wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Install apt-transport-https and ca-certificates apt: @@ -28,6 +28,7 @@ - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - not wazuh_manager_sources_installation.enabled + - not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Installing Wazuh repository key apt_key: @@ -35,6 +36,7 @@ when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) - not wazuh_manager_sources_installation.enabled + - not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Add Wazuh repositories apt_repository: @@ -45,6 +47,7 @@ changed_when: false when: - not wazuh_manager_sources_installation.enabled + - not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Installing NodeJS repository key (Ubuntu 14) become: true @@ -59,13 +62,14 @@ - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - not wazuh_manager_sources_installation.enabled + - not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Installing NodeJS repository key apt_key: url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) - - not wazuh_manager_sources_installation.enabled + - not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Add NodeSource repositories for Node.js apt_repository: @@ -74,7 +78,7 @@ update_cache: true changed_when: false when: - - not wazuh_manager_sources_installation.enabled + - not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Set Distribution CIS filename for Debian/Ubuntu set_fact: @@ -127,11 +131,10 @@ tags: - config -- name: Debian/Ubuntu | Install wazuh-manager, wazuh-api +- name: Debian/Ubuntu | Install wazuh-manager apt: name: - "wazuh-manager={{ wazuh_manager_version }}" - - "wazuh-api={{ wazuh_manager_version }}" state: present cache_valid_time: 3600 install_recommends: false @@ -140,3 +143,16 @@ tags: init when: - not wazuh_manager_sources_installation.enabled + +- name: Debian/Ubuntu | Install wazuh-api + apt: + name: + - "wazuh-api={{ wazuh_manager_version }}" + state: present + cache_valid_time: 3600 + install_recommends: false + register: wazuh_manager_main_packages_installed + until: wazuh_manager_main_packages_installed is succeeded + tags: init + when: + - not wazuh_api_sources_installation.enabled \ No newline at end of file From 6ba58b68386d9a38b08f630cc01eba2c1fd760b5 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 21 Nov 2019 18:46:11 +0100 Subject: [PATCH 41/89] Add variables for Wazuh Api installation from sources --- .../ansible-wazuh-manager/defaults/main.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 2767ab37..475a50a9 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -29,6 +29,24 @@ wazuh_manager_sources_installation: user_ca_store: null threads: "2" +wazuh_api_sources_installation: + enabled: true + branch: "v3.10.2" + update: "y" + remove: "y" + directory: null + port: 55000 + https: "n" + authd: null + proxy: null + country: null + state: null + locality: null + org_name: null + org_unit: null + common_name: null + password: null + wazuh_manager_config: repo: apt: 'deb https://packages.wazuh.com/3.x/apt/ stable main' From bc4f36582a0b1ed5c3f70c37c9f309da08dbb33d Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:40:48 +0100 Subject: [PATCH 42/89] Remove unused tags from sources installation "include_tasks" --- roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 354beca4..382e33b8 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -159,7 +159,6 @@ - init - include_tasks: "../tasks/installation_from_sources.yml" - tags: manager when: - wazuh_manager_sources_installation.enabled @@ -176,7 +175,6 @@ - init - include_tasks: "../tasks/installation_from_sources.yml" - tags: api when: - wazuh_api_sources_installation.enabled From 8d667131d91f9cbf7a674ae9c6de90d65500284b Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:41:06 +0100 Subject: [PATCH 43/89] Fix conditional for ssl_agent_ca --- roles/wazuh/ansible-wazuh-manager/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index d2c99535..f9d54536 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -28,7 +28,7 @@ chdir: /var/ossec/etc/ tags: - config - when: not wazuh_manager_config.authd.ssl_agent_ca is not none + when: wazuh_manager_config.authd.ssl_agent_ca is not none - name: Copy CA, SSL key and cert for authd copy: From df56764dbda227e7d55c0f509db90097c970977a Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:41:47 +0100 Subject: [PATCH 44/89] Add dpeendencies to Wazuh API. Update nodejs repo installation --- .../tasks/installation_from_sources.yml | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index ef24c238..a0d22133 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -83,7 +83,7 @@ mode: '644' - name: Executing "install.sh" script to build and install the Wazuh Manager - shell: ./install.sh > /tmp/build_manager_log.txt + shell: ./install.sh > /tmp/build_wazuh_manager_log.txt register: installation_result changed_when: installation_result == 0 args: @@ -102,14 +102,31 @@ - name: Install Wazuh API from sources block: + - name: Install dependencies to build Wazuh packages + package: + name: + - make + - gcc + - automake + - autoconf + - libtool + - tar + state: present + - name: Ensure Git is present in the host package: name: git state: present + - name: Modify repo url if host is in Debian family + set_fact: + node_js_repo_type: deb + when: + - ansible_os_family | lower == "debian" + - name: Download script to install Nodejs repository get_url: - url: "{{ node_js_repository_url }}" + url: "https://{{ node_js_repo_type }}.{{ node_js_repo_url }}" dest: "/tmp/setup_nodejs_repo.sh" mode: "0700" @@ -148,7 +165,7 @@ mode: '644' - name: Execute Wazuh API installation script - shell: ./install_api.sh > /tmp/build_api_log.txt + shell: ./install_api.sh > /tmp/build_wazuh_api_log.txt register: install_api changed_when: install_api.rc == 0 args: From 5fd46ab9e4ce46972dbb129e0e44497b840e88d9 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:42:09 +0100 Subject: [PATCH 45/89] Remove conditional from wazuh-api restart handler --- roles/wazuh/ansible-wazuh-manager/handlers/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/handlers/main.yml b/roles/wazuh/ansible-wazuh-manager/handlers/main.yml index 0fac45a1..46f1097b 100644 --- a/roles/wazuh/ansible-wazuh-manager/handlers/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/handlers/main.yml @@ -12,6 +12,4 @@ service: name: wazuh-api state: restarted - enabled: true - when: - - not (ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat' and ansible_distribution_major_version|int < 6) + enabled: true \ No newline at end of file From d91ac23d8c13a0e6efe409ffe35c0da0c3feeaca Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:42:23 +0100 Subject: [PATCH 46/89] Update Nodejs repo variables to make it flexible for deb and rpm --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 475a50a9..84448ae7 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -370,4 +370,5 @@ wazuh_agent_configs: - location: 'System' format: 'eventlog' -node_js_repository_url: https://rpm.nodesource.com/setup_8.x \ No newline at end of file +node_js_repo_url: nodesource.com/setup_8.x +node_js_repo_type: rpm \ No newline at end of file From 32dd2e5df5c0348c99a69d7cdaf87ae6d320959c Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:42:56 +0100 Subject: [PATCH 47/89] Rename "preloaded_vars" to "preloaded_vars_agent" --- .../{preloaded_vars.conf.j2 => preloaded_vars_agent.conf.j2} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename roles/wazuh/ansible-wazuh-agent/templates/{preloaded_vars.conf.j2 => preloaded_vars_agent.conf.j2} (61%) diff --git a/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 b/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars_agent.conf.j2 similarity index 61% rename from roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 rename to roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars_agent.conf.j2 index be552560..0887b367 100644 --- a/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars.conf.j2 +++ b/roles/wazuh/ansible-wazuh-agent/templates/preloaded_vars_agent.conf.j2 @@ -1,4 +1,4 @@ -{% for key, value in wazuh_manager_sources_installation.items() %} +{% for key, value in wazuh_agent_sources_installation.items() %} {% if "user_" in key %} {% if value is defined and value is not none %} {{ key|upper }}="{{ value }}" From cbad3e06a2bfd115229cd54a4fffee2c05965fc7 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:43:10 +0100 Subject: [PATCH 48/89] Fix sources conditionals for RedHat.yml --- roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml index e9580a94..76ed0f76 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml @@ -10,7 +10,8 @@ when: - (ansible_facts['os_family']|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) - - not wazuh_manager_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled + - not wazuh_api_sources_installation.enabled register: repo_v5_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo @@ -23,7 +24,7 @@ changed_when: false when: - repo_v5_installed is skipped - - not wazuh_manager_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled - name: RedHat/CentOS/Fedora | download Oracle Java RPM get_url: From f60f218c8824ab332360d3fecad40f3d90ca1ef5 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:43:38 +0100 Subject: [PATCH 49/89] Fix agent installation from sources. Update conditionals and includes --- roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml index 9c8db0b8..9265ce92 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Linux.yml @@ -1,14 +1,14 @@ --- -- include_tasks: "../tasks/installation_from_sources.yml" - when: - - wazuh_manager_sources_installation.enabled - - include_tasks: "RedHat.yml" when: ansible_os_family == "RedHat" - include_tasks: "Debian.yml" when: ansible_os_family == "Debian" +- include_tasks: "installation_from_sources.yml" + when: + - wazuh_agent_sources_installation.enabled + - name: Linux CentOS/RedHat | Install wazuh-agent package: name: wazuh-agent-{{ wazuh_agent_version }} @@ -17,7 +17,7 @@ poll: 30 when: - ansible_os_family|lower == "redhat" - - not wazuh_manager_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled tags: - init @@ -28,7 +28,7 @@ cache_valid_time: 3600 when: - ansible_os_family|lower != "redhat" - - not wazuh_manager_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled tags: - init @@ -200,9 +200,9 @@ - include_tasks: "RMRedHat.yml" when: - ansible_os_family == "RedHat" - - not wazuh_manager_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled - include_tasks: "RMDebian.yml" when: - ansible_os_family == "Debian" - - not wazuh_manager_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled From 66ac8fea816f6c4c5f0e90b6e2129bf8c77e22b5 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:44:05 +0100 Subject: [PATCH 50/89] Fix naming copied from agent. Fix linting --- .../tasks/installation_from_sources.yml | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index 55714673..afc3605f 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -28,26 +28,31 @@ - name: Download required packages from github.com/wazuh/wazuh get_url: - url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_manager_sources_installation.branch }}.tar.gz" - dest: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" + url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_agent_sources_installation.branch }}.tar.gz" + dest: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" delegate_to: "{{ inventory_hostname }}" - name: Create folder to extract Wazuh branch file: - path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" + path: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" state: directory - name: Extract downloaded Wazuh branch from Github # Using shell instead of unarchive due to that module not working properlyh with --strip - command: "tar -xzvf /tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz --strip 1 --directory /tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" + command: >- + tar -xzvf /tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz + --strip 1 + --directory /tmp/wazuh-{{ wazuh_agent_sources_installation.branch }} register: wazuh_untar changed_when: wazuh_untar.rc ==0 args: warn: false + tags: + - molecule-idempotence-notest - name: Clean remaining files from others builds command: "make -C src {{ item }}" args: - chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/src/" + chdir: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}/src/" with_items: - "clean" - "clean-deps" @@ -57,15 +62,17 @@ - name: Render the "preloaded-vars.conf" file template: - src: "templates/preloaded_vars.conf.j2" - dest: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}/etc/preloaded-vars.conf" + src: "templates/preloaded_vars_agent.conf.j2" + dest: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}/etc/preloaded-vars.conf" owner: root group: root mode: '644' + tags: + - molecule-idempotence-notest - name: Executing "install.sh" script to build and install the Wazuh Agent - shell: ./install.sh > /tmp/build_log.txt + shell: ./install.sh > /tmp/build_agent_log.txt register: installation_result changed_when: installation_result == 0 args: - chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" \ No newline at end of file + chdir: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" \ No newline at end of file From ce3dcf7abe9ba20210dec8ccef8058a287b60444 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:44:24 +0100 Subject: [PATCH 51/89] Fix sources conditionals in Debian.yml tasks --- roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml index 329fab6d..0e0ba92f 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/Debian.yml @@ -20,13 +20,14 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - - not wazuh_manager_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled - name: Debian/Ubuntu | Installing Wazuh repository key apt_key: url: "{{ wazuh_agent_config.repo.gpg }}" when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) + - not wazuh_agent_sources_installation.enabled - name: Debian/Ubuntu | Add Wazuh repositories apt_repository: @@ -35,7 +36,7 @@ state: present update_cache: true when: - - not wazuh_manager_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled - name: Debian/Ubuntu | Set Distribution CIS filename for debian set_fact: From 329910eb4191af1c3668d2ca8f12d49185596096 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:45:14 +0100 Subject: [PATCH 52/89] Solve typo in default Agent variables --- roles/wazuh/ansible-wazuh-agent/defaults/main.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index 3ff7d803..28e807f3 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -1,6 +1,7 @@ --- wazuh_agent_version: 3.10.2-1 -wazuh_manager_sources_installation: + +wazuh_agent_sources_installation: enabled: "true" branch: "v3.10.2" user_language: "y" @@ -342,4 +343,4 @@ wazuh_agent_config: list: - key: Env value: Production -wazuh_agent_nat: false +wazuh_agent_nat: false \ No newline at end of file From c988e6220ea8de6d811c59c9b8282b815d1f4a2d Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:45:37 +0100 Subject: [PATCH 53/89] Add custom repo for Wazuh Plugin Kibana installation app --- .../ansible-kibana/tasks/build_wazuh_plugin.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml index 494bc8f0..f4f8fd80 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml @@ -5,9 +5,15 @@ name: git state: present + - name: Modify repo url if host is in Debian family + set_fact: + node_js_repo_type: deb + when: + - ansible_os_family | lower == "debian" + - name: Download script to install Nodejs repository get_url: - url: "{{ node_js_repository_url }}" + url: "https://{{ node_js_repo_type }}.{{ node_js_repo_url }}" dest: "/tmp/setup_nodejs_repo.sh" mode: "0700" From c87da91104d5b7c87d3fdd9a5676a14be0126718 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 15:46:49 +0100 Subject: [PATCH 54/89] Add Kibana default vars to install Nodejs --- roles/elastic-stack/ansible-kibana/defaults/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/roles/elastic-stack/ansible-kibana/defaults/main.yml b/roles/elastic-stack/ansible-kibana/defaults/main.yml index f6ac7023..1352e352 100644 --- a/roles/elastic-stack/ansible-kibana/defaults/main.yml +++ b/roles/elastic-stack/ansible-kibana/defaults/main.yml @@ -25,8 +25,9 @@ generate_CA: true ca_cert_name: "" # Nodejs -node_js_repository_url: https://rpm.nodesource.com/setup_8.x +node_js_repo_url: https://rpm.nodesource.com/setup_8.x +node_js_repo_type: rpm # Build from sources -build_from_sources: true -wazuh_plugin_branch: 3.10-7.4 \ No newline at end of file +build_from_sources: false +wazuh_plugin_branch: 3.10-7.3 \ No newline at end of file From 2efe6e626831263bd9a0206b07d05cdc964ceaa6 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 16:04:06 +0100 Subject: [PATCH 55/89] Restore playbook wazuh-elastic_stack-single.yml to default configuration --- playbooks/wazuh-elastic_stack-single.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/playbooks/wazuh-elastic_stack-single.yml b/playbooks/wazuh-elastic_stack-single.yml index bc353dfd..6558e255 100644 --- a/playbooks/wazuh-elastic_stack-single.yml +++ b/playbooks/wazuh-elastic_stack-single.yml @@ -1,8 +1,8 @@ --- - hosts: all roles: - # - {role: ../roles/wazuh/ansible-wazuh-manager} - # - role: ../roles/wazuh/ansible-filebeat - # filebeat_output_elasticsearch_hosts: 172.24.1.2:9200 - # - {role: ../roles/elastic-stack/ansible-elasticsearch, elasticsearch_network_host: '0.0.0.0', single_node: true} - - { role: ../roles/elastic-stack/ansible-kibana, elasticsearch_network_host: '172.24.1.1', elasticsearch_reachable_host: '172.24.1.2' } + - {role: ../roles/wazuh/ansible-wazuh-manager} + - role: ../roles/wazuh/ansible-filebeat + filebeat_output_elasticsearch_hosts: localhost:9200 + - {role: ../roles/elastic-stack/ansible-elasticsearch, elasticsearch_network_host: '0.0.0.0', single_node: true} + - { role: ../roles/elastic-stack/ansible-kibana, elasticsearch_network_host: 'localhost', elasticsearch_reachable_host: 'localhost' }s \ No newline at end of file From 61d05a0cdde62c8751488235d9df65598ca56ae9 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 16:16:50 +0100 Subject: [PATCH 56/89] Fix linting in Ansible playbooks related with Elastic --- playbooks/wazuh-elastic.yml | 2 +- playbooks/wazuh-elastic_stack-distributed.yml | 8 ++++---- playbooks/wazuh-elastic_stack-single.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/playbooks/wazuh-elastic.yml b/playbooks/wazuh-elastic.yml index 36bd9b1d..eda19931 100644 --- a/playbooks/wazuh-elastic.yml +++ b/playbooks/wazuh-elastic.yml @@ -1,5 +1,5 @@ --- - hosts: roles: - - role: /etc/ansible/roles/wazuh-ansible/roles/elastic-stack/ansible-elasticsearch + - role: /etc/ansible/roles/wazuh-ansible/roles/elastic-stack/ansible-elasticsearch elasticsearch_network_host: '' diff --git a/playbooks/wazuh-elastic_stack-distributed.yml b/playbooks/wazuh-elastic_stack-distributed.yml index 8c6bc567..5f4213f5 100644 --- a/playbooks/wazuh-elastic_stack-distributed.yml +++ b/playbooks/wazuh-elastic_stack-distributed.yml @@ -6,7 +6,7 @@ elasticsearch_network_host: node_name: node-1 elasticsearch_bootstrap_node: true - elasticsearch_cluster_nodes: + elasticsearch_cluster_nodes: - - - @@ -22,7 +22,7 @@ vars: instances: node1: - name: node-1 # Important: must be equal to elasticsearch_node_name. + name: node-1 # Important: must be equal to elasticsearch_node_name. ip: # When unzipping, the node will search for its node name folder to get the cert. node2: name: node-2 @@ -43,10 +43,10 @@ - - - - + - hosts: roles: - - role: /etc/ansible/roles/wazuh-ansible/roles/elastic-stack/ansible-elasticsearch + - role: /etc/ansible/roles/wazuh-ansible/roles/elastic-stack/ansible-elasticsearch elasticsearch_network_host: elasticsearch_node_name: node-3 single_node: false diff --git a/playbooks/wazuh-elastic_stack-single.yml b/playbooks/wazuh-elastic_stack-single.yml index 6558e255..9bf5f0fa 100644 --- a/playbooks/wazuh-elastic_stack-single.yml +++ b/playbooks/wazuh-elastic_stack-single.yml @@ -5,4 +5,4 @@ - role: ../roles/wazuh/ansible-filebeat filebeat_output_elasticsearch_hosts: localhost:9200 - {role: ../roles/elastic-stack/ansible-elasticsearch, elasticsearch_network_host: '0.0.0.0', single_node: true} - - { role: ../roles/elastic-stack/ansible-kibana, elasticsearch_network_host: 'localhost', elasticsearch_reachable_host: 'localhost' }s \ No newline at end of file + - { role: ../roles/elastic-stack/ansible-kibana, elasticsearch_network_host: 'localhost', elasticsearch_reachable_host: 'localhost' } \ No newline at end of file From f57840b2e7ec2203c7d5fd43455c5c6479f5bb90 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 18:11:27 +0100 Subject: [PATCH 57/89] Merge #330 from wazuh/ansible --- .../ansible-wazuh-manager/defaults/main.yml | 7 ++-- .../ansible-wazuh-manager/tasks/Debian.yml | 31 ---------------- .../ansible-wazuh-manager/tasks/RedHat.yml | 36 ------------------- 3 files changed, 5 insertions(+), 69 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 84448ae7..92fbf13c 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -370,5 +370,8 @@ wazuh_agent_configs: - location: 'System' format: 'eventlog' -node_js_repo_url: nodesource.com/setup_8.x -node_js_repo_type: rpm \ No newline at end of file +nodejs: + repo_dic: + debian: "deb" + redhat: "rpm" + repo_url_ext: "nodesource.com/setup_8.x" \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index 6da6a6f3..2c2db72d 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -49,37 +49,6 @@ - not wazuh_manager_sources_installation.enabled - not wazuh_api_sources_installation.enabled -- name: Debian/Ubuntu | Installing NodeJS repository key (Ubuntu 14) - become: true - shell: | - set -o pipefail - curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - - args: - warn: false - executable: /bin/bash - changed_when: false - when: - - ansible_distribution == "Ubuntu" - - ansible_distribution_major_version | int == 14 - - not wazuh_manager_sources_installation.enabled - - not wazuh_api_sources_installation.enabled - -- name: Debian/Ubuntu | Installing NodeJS repository key - apt_key: - url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key - when: - - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) - - not wazuh_api_sources_installation.enabled - -- name: Debian/Ubuntu | Add NodeSource repositories for Node.js - apt_repository: - repo: "deb https://deb.nodesource.com/node_6.x {{ ansible_distribution_release }} main" - state: present - update_cache: true - changed_when: false - when: - - not wazuh_api_sources_installation.enabled - - name: Debian/Ubuntu | Set Distribution CIS filename for Debian/Ubuntu set_fact: cis_distribution_filename: cis_debian_linux_rcl.txt diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 382e33b8..68bf381f 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,40 +1,4 @@ --- - -- name: RedHat/CentOS | Install Nodejs repo - yum_repository: - name: NodeJS - description: NodeJS-$releasever - baseurl: https://rpm.nodesource.com/pub_6.x/el/{{ ansible_distribution_major_version }}/x86_64 - gpgkey: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL - gpgcheck: true - changed_when: false - when: - - ansible_distribution_major_version|int > 5 - - not wazuh_api_sources_installation.enabled - -- name: Fedora | Install Nodejs repo - yum_repository: - name: NodeJS - description: NodeJS-$releasever - baseurl: https://rpm.nodesource.com/pub_6.x/fc/$releasever/x86_64 - gpgkey: https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL - gpgcheck: true - when: - - ansible_distribution == 'Fedora' - - not wazuh_api_sources_installation.enabled - -- name: AmazonLinux | Get Nodejs - shell: | - set -o pipefail - curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - - args: - warn: false - executable: /bin/bash - creates: /etc/yum.repos.d/nodesource-el7.repo - when: - - ansible_distribution|lower == "amazon" - - not wazuh_api_sources_installation.enabled - - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: name: wazuh_repo From 9c2ce76f0919ee1aebc976fe95668b3bb242eb23 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 18:44:00 +0100 Subject: [PATCH 58/89] Fix linting --- .../tasks/installation_from_sources.yml | 26 +++++++++---------- .../tasks/installation_from_sources.yml | 6 ++--- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index 70c3b5af..2b29a682 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -9,14 +9,14 @@ - libtool - tar state: present - - - name: Removing old files - file: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" - state: absent - - name: Removing old folders - file: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" - state: absent + - name: Removing old files + file: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" + state: absent + + - name: Removing old folders + file: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" + state: absent - name: Installing policycoreutils-python (RedHat families) package: @@ -85,10 +85,10 @@ args: chdir: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" - - name: Cleanup downloaded files - file: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" - state: absent + - name: Cleanup downloaded files + file: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" + state: absent - - name: Cleanup created folders - file: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" - state: absent \ No newline at end of file + - name: Cleanup created folders + file: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" + state: absent \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 69d27cfd..411254b1 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -24,7 +24,7 @@ - name: Removing old folders file: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" - state: absent + state: absent - name: Installing policycoreutils-python (RedHat families) package: @@ -167,6 +167,4 @@ - not wazuh_api.stat.exists - wazuh_api_sources_installation.enabled tags: - - api - - \ No newline at end of file + - api \ No newline at end of file From c9c00b82c2fb88f592373451a72ee55a588093c4 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 18:44:09 +0100 Subject: [PATCH 59/89] Add Nodejs installation --- .../ansible-wazuh-manager/tasks/main.yml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index f9d54536..c6f0ae26 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -7,6 +7,34 @@ - tar state: present +- name: Check if NodeJS service exists + stat: + path: /usr/bin/node + register: node_service_status + +- name: Install NodeJS repository + block: + - name: Download NodeJS repository script + get_url: + url: "https://{{ nodejs['repo_dic'][ansible_os_family|lower] }}.{{ nodejs['repo_url_ext'] }}" + dest: /etc/nodejs.sh + mode: '0775' + changed_when: false + + - name: Run NodeJS bash script + command: sh /etc/nodejs.sh + register: nodejs_script + changed_when: nodejs_script.rc == 0 + when: not node_service_status.stat.exists + +- name: Installing NodeJS + package: + name: nodejs + state: present + register: nodejs_service_is_installed + until: nodejs_service_is_installed is succeeded + tags: init + - include_tasks: "RedHat.yml" when: (ansible_os_family == "RedHat" and ansible_distribution_major_version|int > 5) or (ansible_os_family == "RedHat" and ansible_distribution == "Amazon") From fa0e3f16408af2497792eb25998eb5d3d322d8af Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 18:54:21 +0100 Subject: [PATCH 60/89] Fix cleanup tasks for Wazuh Manager and Agent --- .../tasks/installation_from_sources.yml | 20 +++++++++++-------- .../tasks/installation_from_sources.yml | 20 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index 2b29a682..b13c17ef 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -11,12 +11,14 @@ state: present - name: Removing old files - file: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" - state: absent + file: + path: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" + state: absent - name: Removing old folders - file: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" - state: absent + file: + path: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" + state: absent - name: Installing policycoreutils-python (RedHat families) package: @@ -86,9 +88,11 @@ chdir: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" - name: Cleanup downloaded files - file: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" - state: absent + file: + path: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" + state: absent - name: Cleanup created folders - file: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" - state: absent \ No newline at end of file + file: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" + path: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" + state: absent \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 411254b1..1bc17d9d 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -19,12 +19,14 @@ state: present - name: Removing old files - file: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" - state: absent + file: + path: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" + state: absent - name: Removing old folders - file: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" - state: absent + file: + path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" + state: absent - name: Installing policycoreutils-python (RedHat families) package: @@ -98,12 +100,14 @@ chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" - name: Cleanup downloaded files - file: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" - state: absent + file: + path: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" + state: absent - name: Cleanup created folders - file: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" - state: absent + file: + path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" + state: absent when: - not wazuh_ossec_control.stat.exists From fd50b604850d7a77809e19af06146cd65923605e Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 19:01:02 +0100 Subject: [PATCH 61/89] Fix linting --- .../tasks/installation_from_sources.yml | 8 ++++---- .../tasks/installation_from_sources.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index b13c17ef..b426df58 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -11,12 +11,12 @@ state: present - name: Removing old files - file: + file: path: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" state: absent - name: Removing old folders - file: + file: path: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" state: absent @@ -88,11 +88,11 @@ chdir: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" - name: Cleanup downloaded files - file: + file: path: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" state: absent - name: Cleanup created folders - file: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" + file: path: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" state: absent \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 1bc17d9d..7e28a70e 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -19,12 +19,12 @@ state: present - name: Removing old files - file: + file: path: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" state: absent - name: Removing old folders - file: + file: path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" state: absent @@ -100,12 +100,12 @@ chdir: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" - name: Cleanup downloaded files - file: + file: path: "/tmp/{{ wazuh_manager_sources_installation.branch }}.tar.gz" state: absent - name: Cleanup created folders - file: + file: path: "/tmp/wazuh-{{ wazuh_manager_sources_installation.branch }}" state: absent From 3406109b33ca3d05eac3d308ef96ab90abd668f7 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 19:35:23 +0100 Subject: [PATCH 62/89] Remove tags from "preloaded-vars.conf" --- .../ansible-wazuh-agent/tasks/installation_from_sources.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index b426df58..4c4a2c82 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -77,8 +77,6 @@ owner: root group: root mode: '644' - tags: - - molecule-idempotence-notest - name: Executing "install.sh" script to build and install the Wazuh Agent shell: ./install.sh > /tmp/build_agent_log.txt From a4f68f6487dfb46c4ce62ccba3725bb6bf904fa3 Mon Sep 17 00:00:00 2001 From: Jose M Date: Mon, 25 Nov 2019 20:04:28 +0100 Subject: [PATCH 63/89] Remove molecule-idemptence-notest tag to fix Jenkins build --- .../ansible-wazuh-agent/tasks/installation_from_sources.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index 4c4a2c82..0cca7044 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -56,8 +56,6 @@ changed_when: wazuh_untar.rc ==0 args: warn: false - tags: - - molecule-idempotence-notest - name: Clean remaining files from others builds command: "make -C src {{ item }}" From b4352beda178e54f4aeebfc0dd438832c4248ab9 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 00:39:19 +0100 Subject: [PATCH 64/89] Add changed_when conditionals to avoid idempotence errors --- .../tasks/installation_from_sources.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml index 0cca7044..69934631 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/installation_from_sources.yml @@ -41,11 +41,13 @@ url: "https://github.com/wazuh/wazuh/archive/{{ wazuh_agent_sources_installation.branch }}.tar.gz" dest: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" delegate_to: "{{ inventory_hostname }}" + changed_when: false - name: Create folder to extract Wazuh branch file: path: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" state: directory + changed_when: false - name: Extract downloaded Wazuh branch from Github # Using shell instead of unarchive due to that module not working properlyh with --strip command: >- @@ -53,7 +55,7 @@ --strip 1 --directory /tmp/wazuh-{{ wazuh_agent_sources_installation.branch }} register: wazuh_untar - changed_when: wazuh_untar.rc ==0 + changed_when: false args: warn: false @@ -75,6 +77,7 @@ owner: root group: root mode: '644' + changed_when: false - name: Executing "install.sh" script to build and install the Wazuh Agent shell: ./install.sh > /tmp/build_agent_log.txt @@ -87,8 +90,10 @@ file: path: "/tmp/{{ wazuh_agent_sources_installation.branch }}.tar.gz" state: absent + changed_when: false - name: Cleanup created folders file: path: "/tmp/wazuh-{{ wazuh_agent_sources_installation.branch }}" - state: absent \ No newline at end of file + state: absent + changed_when: false \ No newline at end of file From dc0811e6690b901d8e6abfa3cec18e02223decc1 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 01:13:09 +0100 Subject: [PATCH 65/89] Testing Manager: sources, API packages --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 92fbf13c..3d1615f4 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -30,7 +30,7 @@ wazuh_manager_sources_installation: threads: "2" wazuh_api_sources_installation: - enabled: true + enabled: false branch: "v3.10.2" update: "y" remove: "y" From 37a59e212e3fa472a15faa0681ebf991cbc8835e Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 01:14:51 +0100 Subject: [PATCH 66/89] Testing, Manager: package, API: package --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 3d1615f4..90d7fed3 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -5,7 +5,7 @@ wazuh_manager_fqdn: "wazuh-server" wazuh_manager_package_state: present wazuh_manager_sources_installation: - enabled: true + enabled: false branch: "v3.10.2" user_language: "en" user_no_stop: "y" From 0e196abb51c38a432e51737ab1c5d31e3968f43a Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 10:35:34 +0100 Subject: [PATCH 67/89] Add npm as dependency required for Debian 10 --- .../ansible-wazuh-manager/tasks/installation_from_sources.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 7e28a70e..89b934e8 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -133,6 +133,7 @@ - autoconf - libtool - tar + - npm state: present - name: Ensure Git is present in the host From 85db46bbd89db0b8f6439fc7a3261762eb3fcbed Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 10:50:03 +0100 Subject: [PATCH 68/89] Set installation type to sources --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 90d7fed3..92fbf13c 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -5,7 +5,7 @@ wazuh_manager_fqdn: "wazuh-server" wazuh_manager_package_state: present wazuh_manager_sources_installation: - enabled: false + enabled: true branch: "v3.10.2" user_language: "en" user_no_stop: "y" @@ -30,7 +30,7 @@ wazuh_manager_sources_installation: threads: "2" wazuh_api_sources_installation: - enabled: false + enabled: true branch: "v3.10.2" update: "y" remove: "y" From c17424b4639a7916548540f612c51ac1a246176a Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 11:28:22 +0100 Subject: [PATCH 69/89] Limit the npm installation to Debian hosts only --- .../tasks/installation_from_sources.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 89b934e8..420992e6 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -133,8 +133,14 @@ - autoconf - libtool - tar - - npm state: present + + - name: Explicitly installing npm for Debian hosts + package: + name: npm + state: present + when: + - ansible_distribution == "Debian" - name: Ensure Git is present in the host package: From e4fdb984d6ad2b538a442ab205a0e55837d8dc7f Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 11:38:54 +0100 Subject: [PATCH 70/89] Fix Linting --- .../ansible-wazuh-manager/tasks/installation_from_sources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml index 420992e6..b92e4edc 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_sources.yml @@ -134,7 +134,7 @@ - libtool - tar state: present - + - name: Explicitly installing npm for Debian hosts package: name: npm From 94ed23c60788c33cb9afadcb454770457d87fc16 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 13:22:42 +0100 Subject: [PATCH 71/89] Testing Agent from packages. Testing sources/package for manager and api --- roles/wazuh/ansible-wazuh-agent/defaults/main.yml | 2 +- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml index 28e807f3..64935264 100644 --- a/roles/wazuh/ansible-wazuh-agent/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-agent/defaults/main.yml @@ -2,7 +2,7 @@ wazuh_agent_version: 3.10.2-1 wazuh_agent_sources_installation: - enabled: "true" + enabled: "false" branch: "v3.10.2" user_language: "y" user_no_stop: "y" diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 92fbf13c..3d1615f4 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -30,7 +30,7 @@ wazuh_manager_sources_installation: threads: "2" wazuh_api_sources_installation: - enabled: true + enabled: false branch: "v3.10.2" update: "y" remove: "y" From a25b7d9681fa30d05e975388549f33f5ce2b2906 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 14:55:57 +0100 Subject: [PATCH 72/89] Fix conditionals related with Manager and API kind of installatioin --- roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml | 3 +-- roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml | 9 +++------ roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 3 +-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml index 76ed0f76..e0b2b426 100644 --- a/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-agent/tasks/RedHat.yml @@ -10,8 +10,7 @@ when: - (ansible_facts['os_family']|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) - - not wazuh_agent_sources_installation.enabled - - not wazuh_api_sources_installation.enabled + - not wazuh_agent_sources_installation.enabled or not wazuh_api_sources_installation.enabled register: repo_v5_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index 2c2db72d..9752545a 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -27,16 +27,14 @@ when: - ansible_distribution == "Ubuntu" - ansible_distribution_major_version | int == 14 - - not wazuh_manager_sources_installation.enabled - - not wazuh_api_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled or not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Installing Wazuh repository key apt_key: url: "{{ wazuh_manager_config.repo.gpg }}" when: - not (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int == 14) - - not wazuh_manager_sources_installation.enabled - - not wazuh_api_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled or not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Add Wazuh repositories apt_repository: @@ -46,8 +44,7 @@ update_cache: true changed_when: false when: - - not wazuh_manager_sources_installation.enabled - - not wazuh_api_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled or not wazuh_api_sources_installation.enabled - name: Debian/Ubuntu | Set Distribution CIS filename for Debian/Ubuntu set_fact: diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 68bf381f..807275f1 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -10,8 +10,7 @@ when: - (ansible_os_family|lower == 'redhat') and (ansible_distribution|lower != 'amazon') - (ansible_distribution_major_version|int <= 5) - - not wazuh_manager_sources_installation.enabled - - not wazuh_api_sources_installation.enabled + - not wazuh_manager_sources_installation.enabled or not wazuh_api_sources_installation.enabled register: repo_v5_manager_installed - name: RedHat/CentOS/Fedora | Install Wazuh repo From c772d5c983b3e9aa53fd45d7b6798aa2ff03a125 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 15:00:22 +0100 Subject: [PATCH 73/89] Fix Nodejs in Kibana and rename 'repo_dic' to 'repo_dict' --- roles/elastic-stack/ansible-kibana/defaults/main.yml | 7 +++++-- .../ansible-kibana/tasks/build_wazuh_plugin.yml | 3 ++- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- roles/wazuh/ansible-wazuh-manager/tasks/main.yml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/roles/elastic-stack/ansible-kibana/defaults/main.yml b/roles/elastic-stack/ansible-kibana/defaults/main.yml index 1352e352..db42b801 100644 --- a/roles/elastic-stack/ansible-kibana/defaults/main.yml +++ b/roles/elastic-stack/ansible-kibana/defaults/main.yml @@ -25,8 +25,11 @@ generate_CA: true ca_cert_name: "" # Nodejs -node_js_repo_url: https://rpm.nodesource.com/setup_8.x -node_js_repo_type: rpm +nodejs: + repo_dict: + debian: "deb" + redhat: "rpm" + repo_url_ext: "nodesource.com/setup_8.x" # Build from sources build_from_sources: false diff --git a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml index f4f8fd80..b864afc3 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml @@ -13,7 +13,8 @@ - name: Download script to install Nodejs repository get_url: - url: "https://{{ node_js_repo_type }}.{{ node_js_repo_url }}" + nodejs['repo_dict'][ansible_os_family|lower] + url: "https://{{ nodejs['repo_dict'][ansible_os_family|lower] }}.{{ nodejs['repo_url_ext'] }}" dest: "/tmp/setup_nodejs_repo.sh" mode: "0700" diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 3d1615f4..f85e32eb 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -371,7 +371,7 @@ wazuh_agent_configs: format: 'eventlog' nodejs: - repo_dic: + repo_dict: debian: "deb" redhat: "rpm" repo_url_ext: "nodesource.com/setup_8.x" \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index c6f0ae26..0bb00fef 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -16,7 +16,7 @@ block: - name: Download NodeJS repository script get_url: - url: "https://{{ nodejs['repo_dic'][ansible_os_family|lower] }}.{{ nodejs['repo_url_ext'] }}" + url: "https://{{ nodejs['repo_dict'][ansible_os_family|lower] }}.{{ nodejs['repo_url_ext'] }}" dest: /etc/nodejs.sh mode: '0775' changed_when: false From e18e95816004b76cab8a46aa5841d371f56a8fb7 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 16:38:40 +0100 Subject: [PATCH 74/89] Fix typo in build_wazuh_plugin.yml --- roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml index b864afc3..4a2ebc23 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml @@ -1,5 +1,4 @@ --- - - name: Ensure the Git package is present package: name: git @@ -13,7 +12,6 @@ - name: Download script to install Nodejs repository get_url: - nodejs['repo_dict'][ansible_os_family|lower] url: "https://{{ nodejs['repo_dict'][ansible_os_family|lower] }}.{{ nodejs['repo_url_ext'] }}" dest: "/tmp/setup_nodejs_repo.sh" mode: "0700" From ad8ae0ed655205f062ef50bead632e2a1448177c Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 17:53:24 +0100 Subject: [PATCH 75/89] Testing package/sources for Manager and API respectively --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index f85e32eb..ca23f8ff 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -5,7 +5,7 @@ wazuh_manager_fqdn: "wazuh-server" wazuh_manager_package_state: present wazuh_manager_sources_installation: - enabled: true + enabled: false branch: "v3.10.2" user_language: "en" user_no_stop: "y" @@ -30,7 +30,7 @@ wazuh_manager_sources_installation: threads: "2" wazuh_api_sources_installation: - enabled: false + enabled: true branch: "v3.10.2" update: "y" remove: "y" From 4ba0a85bf199511278d127a774e3e81f6b0b4ce8 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 18:49:10 +0100 Subject: [PATCH 76/89] Fix includes for wazuh-manager role --- roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml | 8 ++++---- roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index 9752545a..e045059d 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -1,8 +1,4 @@ --- -- include_tasks: "installation_from_sources.yml" - when: - - wazuh_manager_sources_installation.enabled or wazuh_api_sources_installation.enabled - - name: Debian/Ubuntu | Install apt-transport-https and ca-certificates apt: name: @@ -110,6 +106,10 @@ when: - not wazuh_manager_sources_installation.enabled +- include_tasks: "installation_from_sources.yml" + when: + - wazuh_manager_sources_installation.enabled or wazuh_api_sources_installation.enabled + - name: Debian/Ubuntu | Install wazuh-api apt: name: diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 807275f1..49ff0cdf 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -137,10 +137,6 @@ tags: - init -- include_tasks: "../tasks/installation_from_sources.yml" - when: - - wazuh_api_sources_installation.enabled - - name: CentOS/RedHat 6 | Enabling python2.7 and sqlite3 replace: path: /etc/init.d/wazuh-manager From dbf436be04828e4a0c28abae95ce1da926ada5c0 Mon Sep 17 00:00:00 2001 From: Jose M Date: Tue, 26 Nov 2019 18:56:06 +0100 Subject: [PATCH 77/89] Testing installation from packages --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index ca23f8ff..ad3ddf1d 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -30,7 +30,7 @@ wazuh_manager_sources_installation: threads: "2" wazuh_api_sources_installation: - enabled: true + enabled: false branch: "v3.10.2" update: "y" remove: "y" From ae5a3d6f91f459f2963a257b4d6e1c0ccff7173c Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 27 Nov 2019 10:04:21 +0100 Subject: [PATCH 78/89] Fix conditional for RHEL hosts --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index ad3ddf1d..ca23f8ff 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -30,7 +30,7 @@ wazuh_manager_sources_installation: threads: "2" wazuh_api_sources_installation: - enabled: false + enabled: true branch: "v3.10.2" update: "y" remove: "y" diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 49ff0cdf..fc8cd489 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -123,7 +123,7 @@ - include_tasks: "../tasks/installation_from_sources.yml" when: - - wazuh_manager_sources_installation.enabled + - wazuh_manager_sources_installation.enabled or wazuh_api_sources_installation.enabled - name: CentOS/RedHat/Amazon | Install Wazuh API package: From aaa68bd5bb87c0a8bda4d2fb3aee63ac60aca738 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 27 Nov 2019 11:27:26 +0100 Subject: [PATCH 79/89] Testing installation from packages --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index ca23f8ff..ad3ddf1d 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -30,7 +30,7 @@ wazuh_manager_sources_installation: threads: "2" wazuh_api_sources_installation: - enabled: true + enabled: false branch: "v3.10.2" update: "y" remove: "y" From dec2fc5cca33e001ba8717af2741b5b9874edc64 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 27 Nov 2019 12:50:06 +0100 Subject: [PATCH 80/89] Test Kibana installation from sources --- roles/elastic-stack/ansible-kibana/defaults/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/elastic-stack/ansible-kibana/defaults/main.yml b/roles/elastic-stack/ansible-kibana/defaults/main.yml index db42b801..0a05d853 100644 --- a/roles/elastic-stack/ansible-kibana/defaults/main.yml +++ b/roles/elastic-stack/ansible-kibana/defaults/main.yml @@ -32,5 +32,5 @@ nodejs: repo_url_ext: "nodesource.com/setup_8.x" # Build from sources -build_from_sources: false -wazuh_plugin_branch: 3.10-7.3 \ No newline at end of file +build_from_sources: true +wazuh_plugin_branch: 3.10-7.4 \ No newline at end of file From 814cfa1e5e5cf2f97bfe9ca81a60b1107eac79e8 Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 27 Nov 2019 13:49:12 +0100 Subject: [PATCH 81/89] Fix idempotence on Kibana installation from sources --- .../ansible-kibana/tasks/build_wazuh_plugin.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml index 4a2ebc23..8de3281c 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml @@ -19,7 +19,7 @@ - name: Execute downloaded script to install Nodejs repo command: /tmp/setup_nodejs_repo.sh register: node_repo_installation_result - changed_when: node_repo_installation_result.rc == 0 + changed_when: false - name: Install Nodejs package: @@ -29,7 +29,7 @@ - name: Run NPM under root account command: npm config set user 0 register: allow_root_npm - changed_when: allow_root_npm.rc == 0 + changed_when: false - name: Install yarn dependency to build the Wazuh Kibana Plugin command: npm install -g yarn@1.10.1 @@ -40,11 +40,12 @@ file: path: /tmp/app state: absent + changed_when: false - name: Clone wazuh-kibana-app repository # Using command as git module doesn't cover single-branch nor depth command: git clone https://github.com/wazuh/wazuh-kibana-app -b {{ wazuh_plugin_branch }} --single-branch --depth=1 app # noqa 303 register: clone_app_repo_result - changed_when: clone_app_repo_result.rc == 0 + changed_when: false args: chdir: "/tmp" From 77145e71b867326df92f7904e8e95c1f24ca7a8f Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 27 Nov 2019 18:00:34 +0100 Subject: [PATCH 82/89] Disable Kibana from sources and test sources/package after changes --- roles/elastic-stack/ansible-kibana/defaults/main.yml | 2 +- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/elastic-stack/ansible-kibana/defaults/main.yml b/roles/elastic-stack/ansible-kibana/defaults/main.yml index 0a05d853..8e4a6572 100644 --- a/roles/elastic-stack/ansible-kibana/defaults/main.yml +++ b/roles/elastic-stack/ansible-kibana/defaults/main.yml @@ -32,5 +32,5 @@ nodejs: repo_url_ext: "nodesource.com/setup_8.x" # Build from sources -build_from_sources: true +build_from_sources: false wazuh_plugin_branch: 3.10-7.4 \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index ad3ddf1d..f85e32eb 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -5,7 +5,7 @@ wazuh_manager_fqdn: "wazuh-server" wazuh_manager_package_state: present wazuh_manager_sources_installation: - enabled: false + enabled: true branch: "v3.10.2" user_language: "en" user_no_stop: "y" From eed1a11aebb7e4ffdb68d8548983aad46e6f2af8 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 28 Nov 2019 10:13:08 +0100 Subject: [PATCH 83/89] Testing sources/sources installation for Manager and API respectively --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index f85e32eb..27106dc1 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -30,7 +30,7 @@ wazuh_manager_sources_installation: threads: "2" wazuh_api_sources_installation: - enabled: false + enabled: true branch: "v3.10.2" update: "y" remove: "y" From 50cd3745bb13750572b3ae73bf191c61b7325b9e Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 28 Nov 2019 11:28:38 +0100 Subject: [PATCH 84/89] Add check to stop if trying to build Kibana in Debian 10 --- roles/elastic-stack/ansible-kibana/tasks/main.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/roles/elastic-stack/ansible-kibana/tasks/main.yml b/roles/elastic-stack/ansible-kibana/tasks/main.yml index 89af291c..dd0e423f 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/main.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/main.yml @@ -1,4 +1,13 @@ --- + +- name: Stopping early, trying to compile Wazuh Kibana Plugin on Debian 10 is not possible + fail: + msg: "It's not possible to compile the Wazuh Kibana plugin on Debian 10 due to: https://github.com/wazuh/wazuh-kibana-app/issues/1924" + when: + - build_from_sources + - ansible_distribution == "Debian" + - ansible_distribution_major_version == "10" + - import_tasks: RedHat.yml when: ansible_os_family == 'RedHat' @@ -108,6 +117,7 @@ - build_from_sources is defined - build_from_sources + - name: Install Wazuh Plugin (can take a while) shell: "/usr/share/kibana/bin/kibana-plugin install {{ wazuh_app_url }}-{{ wazuh_version }}_{{ elastic_stack_version }}.zip" environment: From 7f70b4dfebce1484c95db3e8ff623d05871624b4 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 28 Nov 2019 11:49:40 +0100 Subject: [PATCH 85/89] Update "build_wazuh_plugin" to fix conditional and update npm task --- .../ansible-kibana/tasks/build_wazuh_plugin.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml index 8de3281c..a18a752b 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml @@ -26,13 +26,9 @@ name: nodejs state: present - - name: Run NPM under root account - command: npm config set user 0 - register: allow_root_npm - changed_when: false - - name: Install yarn dependency to build the Wazuh Kibana Plugin - command: npm install -g yarn@1.10.1 + # Using shell due to errors when evaluating text between @ with command + shell: "npm install -g {{ 'yarn' }}{{ '@' }}{{ '1.10.1'}}" # noqa 305 register: install_yarn_result changed_when: install_yarn_result == 0 @@ -56,7 +52,7 @@ - "yarn build" - "yarn build" # Executing multiple times to workaround errors returned by yarn build register: yarn_execution_result - changed_when: yarn_execution_result == 0 + changed_when: false args: chdir: "/tmp/app/" From b9a6d0e1d6c2f098480dc04e8309f439b23ee671 Mon Sep 17 00:00:00 2001 From: Jose M Date: Thu, 28 Nov 2019 11:49:47 +0100 Subject: [PATCH 86/89] Testing Kibana from sources --- roles/elastic-stack/ansible-kibana/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/elastic-stack/ansible-kibana/defaults/main.yml b/roles/elastic-stack/ansible-kibana/defaults/main.yml index 8e4a6572..0a05d853 100644 --- a/roles/elastic-stack/ansible-kibana/defaults/main.yml +++ b/roles/elastic-stack/ansible-kibana/defaults/main.yml @@ -32,5 +32,5 @@ nodejs: repo_url_ext: "nodesource.com/setup_8.x" # Build from sources -build_from_sources: false +build_from_sources: true wazuh_plugin_branch: 3.10-7.4 \ No newline at end of file From 7525c75beb3cbb66e0a6822d762713b6220e14a2 Mon Sep 17 00:00:00 2001 From: Jose M Date: Fri, 29 Nov 2019 10:00:19 +0100 Subject: [PATCH 87/89] Restore elastic_stack-single to default configuration --- playbooks/wazuh-elastic_stack-single.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playbooks/wazuh-elastic_stack-single.yml b/playbooks/wazuh-elastic_stack-single.yml index 9bf5f0fa..aba365c9 100644 --- a/playbooks/wazuh-elastic_stack-single.yml +++ b/playbooks/wazuh-elastic_stack-single.yml @@ -1,8 +1,8 @@ --- -- hosts: all +- hosts: roles: - {role: ../roles/wazuh/ansible-wazuh-manager} - role: ../roles/wazuh/ansible-filebeat filebeat_output_elasticsearch_hosts: localhost:9200 - {role: ../roles/elastic-stack/ansible-elasticsearch, elasticsearch_network_host: '0.0.0.0', single_node: true} - - { role: ../roles/elastic-stack/ansible-kibana, elasticsearch_network_host: 'localhost', elasticsearch_reachable_host: 'localhost' } \ No newline at end of file + - { role: ../roles/elastic-stack/ansible-kibana, elasticsearch_network_host: '0.0.0.0', elasticsearch_reachable_host: 'localhost' } \ No newline at end of file From e45aaf6a8e133910e17536aaa7897668fafb9eaf Mon Sep 17 00:00:00 2001 From: Jose M Date: Fri, 29 Nov 2019 10:04:09 +0100 Subject: [PATCH 88/89] Improving description for installation tasks in "RedHat.yml" --- roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index fc8cd489..5dc57e81 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -109,7 +109,7 @@ when: - ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA" -- name: CentOS/RedHat/Amazon | Install Wazuh Manager +- name: CentOS/RedHat/Amazon | Install wazuh-manager package: name: "wazuh-manager-{{ wazuh_manager_version }}" state: "{{ wazuh_manager_package_state }}" @@ -125,7 +125,7 @@ when: - wazuh_manager_sources_installation.enabled or wazuh_api_sources_installation.enabled -- name: CentOS/RedHat/Amazon | Install Wazuh API +- name: CentOS/RedHat/Amazon | Install wazuh-api package: name: "wazuh-api-{{ wazuh_manager_version }}" state: "{{ wazuh_manager_package_state }}" From ab4ef23e2ae9a947ed8585500a434188314bafc8 Mon Sep 17 00:00:00 2001 From: Jose M Date: Fri, 29 Nov 2019 10:51:58 +0100 Subject: [PATCH 89/89] Remove unneeded yarn build execution --- roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml index a18a752b..6a3dc514 100644 --- a/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml +++ b/roles/elastic-stack/ansible-kibana/tasks/build_wazuh_plugin.yml @@ -50,7 +50,6 @@ with_items: - "yarn" - "yarn build" - - "yarn build" # Executing multiple times to workaround errors returned by yarn build register: yarn_execution_result changed_when: false args: