From d85d210a3e5029253b0a30276e60d35233ab8fa1 Mon Sep 17 00:00:00 2001 From: Rshad Zhran Date: Thu, 21 Nov 2019 16:12:08 +0100 Subject: [PATCH] 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