From 4dd780504b0669d6aa7d77fea5711cf58c312b9d Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Wed, 20 Nov 2019 16:33:14 +0100 Subject: [PATCH 01/12] Adapt NodeJS installation tasks in Debian --- .../ansible-wazuh-manager/tasks/Debian.yml | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index b7bc7946..af33e4ba 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -38,31 +38,23 @@ update_cache: true changed_when: false -- name: Debian/Ubuntu | Installing NodeJS repository key (Ubuntu 14) +- name: Debian/Ubuntu | Installing NodeJS repository become: true shell: | set -o pipefail - curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - + curl -sL https://deb.nodesource.com/setup_8.x | bash - args: warn: false executable: /bin/bash changed_when: false - when: - - ansible_distribution == "Ubuntu" - - ansible_distribution_major_version | int == 14 -- 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) - -- name: Debian/Ubuntu | Add NodeSource repositories for Node.js - apt_repository: - repo: "deb https://deb.nodesource.com/node_6.x {{ ansible_distribution_release }} main" +- name: Debian/Ubuntu | Install NodeJS + apt: + name: "nodejs" state: present - update_cache: true - changed_when: false + register: nodejs_package_is_installed + until: nodejs_package_is_installed is succeeded + tags: init - name: Debian/Ubuntu | Set Distribution CIS filename for Debian/Ubuntu set_fact: From da7cfa60b130725f64a6f063f11769a3f4e1a16d Mon Sep 17 00:00:00 2001 From: Jose M Date: Wed, 20 Nov 2019 16:49:11 +0100 Subject: [PATCH 02/12] 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 3c70bc5b2a1e7505971090867378f72fa9219249 Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Thu, 21 Nov 2019 13:13:36 +0100 Subject: [PATCH 03/12] Update NodJS installation tasks --- .../ansible-wazuh-manager/tasks/RedHat.yml | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index c8e8a95a..5503a10c 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,25 +1,5 @@ --- -- 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: Centos | Get Nodejs shell: | set -o pipefail curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - @@ -27,8 +7,28 @@ warn: false executable: /bin/bash creates: /etc/yum.repos.d/nodesource-el7.repo + when: + - ansible_distribution_major_version|int > 5 + +- name: AmazonLinux/Fedora| Get Nodejs + shell: | + set -o pipefail + curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - + args: + warn: false + executable: /bin/bash when: - ansible_distribution|lower == "amazon" + - ansible_distribution == 'Fedora' + +- name: CentOS/RedHat/Amazon/Fedora | Install NodeJS + package: + name: "nodejs" + state: present + register: nodejs_is_installed + until: nodejs_is_installed is succeeded + tags: + - init - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: From e2cee2e45d1cbdba88acf6724347bae4768fa6c7 Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Thu, 21 Nov 2019 14:00:08 +0100 Subject: [PATCH 04/12] fix conditional statement when --- roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 5503a10c..30e0cdc1 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -18,8 +18,7 @@ warn: false executable: /bin/bash when: - - ansible_distribution|lower == "amazon" - - ansible_distribution == 'Fedora' + - ansible_distribution|lower == "amazon" or ansible_distribution|lower == 'fedora' - name: CentOS/RedHat/Amazon/Fedora | Install NodeJS package: From 686c02b3d5d424356bde2df86ed335fb7276291b Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Thu, 21 Nov 2019 14:48:54 +0100 Subject: [PATCH 05/12] Add task to check if node service already exists --- roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml index 30e0cdc1..196d0e3b 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,4 +1,8 @@ --- +- name: Check if NodeJS service Exists + stat: path=/usr/bin/node + register: node_service_status + - name: Centos | Get Nodejs shell: | set -o pipefail @@ -8,7 +12,7 @@ executable: /bin/bash creates: /etc/yum.repos.d/nodesource-el7.repo when: - - ansible_distribution_major_version|int > 5 + - ansible_distribution_major_version|int > 5 and not node_service_status.stat.exists - name: AmazonLinux/Fedora| Get Nodejs shell: | @@ -18,7 +22,7 @@ warn: false executable: /bin/bash when: - - ansible_distribution|lower == "amazon" or ansible_distribution|lower == 'fedora' + - ( ansible_distribution|lower == "amazon" or ansible_distribution|lower == 'fedora' ) and not node_service_status.stat.exists - name: CentOS/RedHat/Amazon/Fedora | Install NodeJS package: @@ -28,6 +32,7 @@ until: nodejs_is_installed is succeeded tags: - init + when: not node_service_status.stat.exists - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: From d85d210a3e5029253b0a30276e60d35233ab8fa1 Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Thu, 21 Nov 2019 16:12:08 +0100 Subject: [PATCH 06/12] Centralize NodeJS installation tasks --- playbooks/wazuh-manager.yml | 4 +++ .../ansible-wazuh-manager/tasks/Debian.yml | 18 ---------- .../ansible-wazuh-manager/tasks/RedHat.yml | 35 ------------------- .../ansible-wazuh-manager/tasks/main.yml | 19 ++++++++++ 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/playbooks/wazuh-manager.yml b/playbooks/wazuh-manager.yml index 5ec6a50b..846d4158 100644 --- a/playbooks/wazuh-manager.yml +++ b/playbooks/wazuh-manager.yml @@ -1,5 +1,9 @@ --- - hosts: +- vars: + - repo_dic: + debian: "deb" + redhat: "rpm" roles: - role: ../roles/wazuh/ansible-wazuh-manager - role: ../roles/wazuh/ansible-filebeat diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml index af33e4ba..b4e94308 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/Debian.yml @@ -38,24 +38,6 @@ update_cache: true changed_when: false -- name: Debian/Ubuntu | Installing NodeJS repository - become: true - shell: | - set -o pipefail - curl -sL https://deb.nodesource.com/setup_8.x | bash - - args: - warn: false - executable: /bin/bash - changed_when: false - -- name: Debian/Ubuntu | Install NodeJS - apt: - name: "nodejs" - state: present - register: nodejs_package_is_installed - until: nodejs_package_is_installed is succeeded - tags: init - - 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 196d0e3b..938bc83d 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/RedHat.yml @@ -1,39 +1,4 @@ --- -- name: Check if NodeJS service Exists - stat: path=/usr/bin/node - register: node_service_status - -- name: Centos | 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_major_version|int > 5 and not node_service_status.stat.exists - -- name: AmazonLinux/Fedora| Get Nodejs - shell: | - set -o pipefail - curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - - args: - warn: false - executable: /bin/bash - when: - - ( ansible_distribution|lower == "amazon" or ansible_distribution|lower == 'fedora' ) and not node_service_status.stat.exists - -- name: CentOS/RedHat/Amazon/Fedora | Install NodeJS - package: - name: "nodejs" - state: present - register: nodejs_is_installed - until: nodejs_is_installed is succeeded - tags: - - init - when: not node_service_status.stat.exists - - name: RedHat/CentOS 5 | Install Wazuh repo yum_repository: name: wazuh_repo diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index ed4847aa..33aa58b7 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -13,6 +13,25 @@ - include_tasks: "Debian.yml" when: ansible_os_family == "Debian" +- name: Installing NodeJS repository script + become: true + get_url: + url: "https://{{ repo_dic[ansible_os_family] }}nodesource.com/setup_8.x" + dest: /etc/nodejs.sh + mode: '0775' + changed_when: false + +- name: Running NodeJS bash script + script: /etc/nodejs.sh + +- name: Installing NodeJS + package: + name: ntpdate + state: present + register: nodejs_service_is_installed + until: nodejs_service_is_installed is succeeded + tags: init + - name: Install expect package: name: expect From 902ee2a3d18fce94e48cfe376dacb13b56664b0b Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Fri, 22 Nov 2019 11:18:09 +0100 Subject: [PATCH 07/12] Add a task to check if nodejs already exists --- roles/wazuh/ansible-wazuh-manager/tasks/main.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index 33aa58b7..2a3b20e0 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -13,20 +13,29 @@ - include_tasks: "Debian.yml" when: ansible_os_family == "Debian" +- name: Check if NodeJS service Exists + stat: + path: /usr/bin/node + register: node_service_status + - name: Installing NodeJS repository script become: true get_url: - url: "https://{{ repo_dic[ansible_os_family] }}nodesource.com/setup_8.x" + url: "https://{{ repo_dic[ansible_os_family|lower] }}.nodesource.com/setup_8.x" dest: /etc/nodejs.sh mode: '0775' changed_when: false + when: not node_service_status.stat.exists - name: Running NodeJS bash script - script: /etc/nodejs.sh + 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: ntpdate + name: nodejs state: present register: nodejs_service_is_installed until: nodejs_service_is_installed is succeeded From c32d992f890e20f3cb4a439509399df802c5ce49 Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Fri, 22 Nov 2019 11:39:08 +0100 Subject: [PATCH 08/12] Re-order tasks --- roles/wazuh/ansible-wazuh-manager/tasks/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index 2a3b20e0..a5ccf343 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -7,12 +7,6 @@ - tar state: present -- 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") - -- include_tasks: "Debian.yml" - when: ansible_os_family == "Debian" - - name: Check if NodeJS service Exists stat: path: /usr/bin/node @@ -41,6 +35,12 @@ 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") + +- include_tasks: "Debian.yml" + when: ansible_os_family == "Debian" + - name: Install expect package: name: expect From 376628a914e93cebaabf105f3208d0e57923ef03 Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Fri, 22 Nov 2019 13:14:48 +0100 Subject: [PATCH 09/12] Define variable in default.yml instead of playbook --- playbooks/wazuh-manager.yml | 4 ---- roles/wazuh/ansible-wazuh-manager/vars/default.yml | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 roles/wazuh/ansible-wazuh-manager/vars/default.yml diff --git a/playbooks/wazuh-manager.yml b/playbooks/wazuh-manager.yml index 846d4158..5ec6a50b 100644 --- a/playbooks/wazuh-manager.yml +++ b/playbooks/wazuh-manager.yml @@ -1,9 +1,5 @@ --- - hosts: -- vars: - - repo_dic: - debian: "deb" - redhat: "rpm" roles: - role: ../roles/wazuh/ansible-wazuh-manager - role: ../roles/wazuh/ansible-filebeat diff --git a/roles/wazuh/ansible-wazuh-manager/vars/default.yml b/roles/wazuh/ansible-wazuh-manager/vars/default.yml new file mode 100644 index 00000000..af1a2fbe --- /dev/null +++ b/roles/wazuh/ansible-wazuh-manager/vars/default.yml @@ -0,0 +1,3 @@ +- repo_dic: + debian: "deb" + redhat: "rpm" \ No newline at end of file From 5fd5ddc61f9befa864c7e37d92698ad48fffa50c Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Fri, 22 Nov 2019 13:16:28 +0100 Subject: [PATCH 10/12] Englobe tasks with same when statement in block --- .../ansible-wazuh-manager/tasks/main.yml | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index a5ccf343..d10f1f2a 100644 --- a/roles/wazuh/ansible-wazuh-manager/tasks/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml @@ -7,24 +7,24 @@ - tar state: present -- name: Check if NodeJS service Exists +- name: Check if NodeJS service exists stat: path: /usr/bin/node register: node_service_status -- name: Installing NodeJS repository script - become: true - get_url: - url: "https://{{ repo_dic[ansible_os_family|lower] }}.nodesource.com/setup_8.x" - dest: /etc/nodejs.sh - mode: '0775' - changed_when: false - when: not node_service_status.stat.exists +- name: Install NodeJS repository + block: + - name: Download NodeJS repository script + get_url: + url: "https://{{ repo_dic[ansible_os_family|lower] }}.nodesource.com/setup_8.x" + dest: /etc/nodejs.sh + mode: '0775' + changed_when: false -- name: Running NodeJS bash script - command: sh /etc/nodejs.sh - register: nodejs_script - changed_when: nodejs_script.rc == 0 + - 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 From 565a84c49f801c934bcecffeda47b7356e334584 Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Fri, 22 Nov 2019 13:38:11 +0100 Subject: [PATCH 11/12] Define variables in default/main.yml --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 3 +++ roles/wazuh/ansible-wazuh-manager/vars/default.yml | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 roles/wazuh/ansible-wazuh-manager/vars/default.yml diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index e66ccae5..069af007 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -326,3 +326,6 @@ wazuh_agent_configs: format: 'eventchannel' - location: 'System' format: 'eventlog' +repo_dic: + debian: "deb" + redhat: "rpm" \ No newline at end of file diff --git a/roles/wazuh/ansible-wazuh-manager/vars/default.yml b/roles/wazuh/ansible-wazuh-manager/vars/default.yml deleted file mode 100644 index af1a2fbe..00000000 --- a/roles/wazuh/ansible-wazuh-manager/vars/default.yml +++ /dev/null @@ -1,3 +0,0 @@ -- repo_dic: - debian: "deb" - redhat: "rpm" \ No newline at end of file From e003a2d51eb3c1fad46baa5e7644ad727796898d Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Mon, 25 Nov 2019 17:39:03 +0100 Subject: [PATCH 12/12] Parameterize NodeJS repo. url --- roles/wazuh/ansible-wazuh-manager/defaults/main.yml | 8 +++++--- roles/wazuh/ansible-wazuh-manager/tasks/main.yml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml index 069af007..66253fef 100644 --- a/roles/wazuh/ansible-wazuh-manager/defaults/main.yml +++ b/roles/wazuh/ansible-wazuh-manager/defaults/main.yml @@ -326,6 +326,8 @@ wazuh_agent_configs: format: 'eventchannel' - location: 'System' format: 'eventlog' -repo_dic: - debian: "deb" - redhat: "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/main.yml b/roles/wazuh/ansible-wazuh-manager/tasks/main.yml index d10f1f2a..d17e29bd 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://{{ repo_dic[ansible_os_family|lower] }}.nodesource.com/setup_8.x" + url: "https://{{ nodejs['repo_dic'][ansible_os_family|lower] }}.{{ nodejs['repo_url_ext'] }}" dest: /etc/nodejs.sh mode: '0775' changed_when: false