diff --git a/.github/workflows/Test_installation_assistant.yml b/.github/workflows/Test_installation_assistant.yml index e115521..a26827f 100644 --- a/.github/workflows/Test_installation_assistant.yml +++ b/.github/workflows/Test_installation_assistant.yml @@ -124,6 +124,15 @@ jobs: repository: wazuh/wazuh-automation ref: ${{ inputs.AUTOMATION_REFERENCE }} token: ${{ secrets.GH_CLONE_TOKEN }} + + - name: Debug workspace + run: ls $GITHUB_WORKSPACE + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Debug workspace + run: ls $GITHUB_WORKSPACE - name: Install and set allocator requirements run: pip3 install -r deployability/deps/requirements.txt @@ -136,19 +145,12 @@ jobs: --label-team devops --label-termination-date 1d sed 's/: */=/g' /tmp/allocator_instance/inventory.yml > /tmp/allocator_instance/inventory_mod.yml + sed -i 's/-o StrictHostKeyChecking=no/\"-o StrictHostKeyChecking=no\"/g' /tmp/allocator_instance/inventory_mod.yml source /tmp/allocator_instance/inventory_mod.yml - echo "[gha_instance]" > /tmp/allocator_instance/inventory_ansible.ini - echo "$ansible_host ansible_port=$ansible_port ansible_user=$ansible_user ansible_ssh_private_key_file=$ansible_ssh_private_key_file ansible_ssh_common_args='$ansible_ssh_common_args'" >> /tmp/allocator_instance/inventory_ansible.ini - - echo "::add-mask::$ansible_host" - echo "::add-mask::$ansible_port" - echo "::add-mask::$ansible_user" - echo "::add-mask::$ansible_ssh_private_key_file" - echo "::add-mask::$ansible_ssh_common_args" - cat "/tmp/allocator_instance/inventory_mod.yml" >> $GITHUB_ENV; - cat /tmp/allocator_instance/inventory_ansible.ini - + echo "[gha_instance]" > /tmp/allocator_instance/inventory + echo "$ansible_host ansible_port=$ansible_port ansible_user=$ansible_user ansible_ssh_private_key_file=$ansible_ssh_private_key_file ansible_ssh_common_args='$ansible_ssh_common_args'" >> /tmp/allocator_instance/inventory + - name: Delete allocated VM if: always() && steps.allocator_instance.outcome == 'success' run: python3 deployability/modules/allocation/main.py --action delete --track-output /tmp/allocator_instance/track.yml \ No newline at end of file diff --git a/.github/workflows/ansible-playbooks/provision.yml b/.github/workflows/ansible-playbooks/provision.yml new file mode 100644 index 0000000..0dc837b --- /dev/null +++ b/.github/workflows/ansible-playbooks/provision.yml @@ -0,0 +1,189 @@ +--- +- hosts: all + become: true + vars: + script_path: "{{ tmp_path }}/unattended_installer" + script_name: "wazuh-install.sh" + rpm_deps: + - git + - python3 + - python3-pip + - openssl + - tar + apt_deps: + - git + - software-properties-common + - gnupg2 + pip_deps: + - attrs==21.1.0 + - importlib-metadata==4.8.2 + - iniconfig==1.1.1 + - packaging==21.3 + - pluggy==1.0.0 + - py==1.11.0 + - pyparsing==3.0.6 + - toml==0.10.2 + - typing-extensions==4.0.0 + - pytest==6.2.5 + - pyyaml + - requests + - setuptools + - beautifulsoup4 + - urllib3==1.26.6 + + tasks: + - name: Make tmp folder directory + file: + path: "{{ tmp_path }}" + state: directory + + - name: Install main deps block + block: + + - name: Install required dependencies DNF + dnf: + name: "{{ rpm_deps }}" + state: present + when: ansible_pkg_mgr == "dnf" + + # --------------------------------------------------------------------- + + - name: Install required dependencies YUM + yum: + name: "{{ rpm_deps }}" + state: present + when: ansible_pkg_mgr == "yum" + + # --------------------------------------------------------------------- + + - name: Install required dependencies APT + apt: + name: "{{ apt_deps }}" + state: present + update_cache: yes + when: ansible_pkg_mgr == "apt" + when: + - install_deps is defined + - install_deps == true + + - name: Install Python and pip + block: + + # --------------------------------------------------------------------- + # Ubuntu -------------------------------------------------------------- + + - name: Set up Python 3.9 repository + apt_repository: + repo: 'ppa:deadsnakes/ppa' + when: + - ansible_pkg_mgr == "apt" + - ansible_distribution == "Ubuntu" + + - name: Install Python3.9 on Ubuntu Jammy + apt: + name: + - python3.9 + - python3.9-distutils + state: present + update_cache: yes + when: + - ansible_pkg_mgr == "apt" + - ansible_distribution == "Ubuntu" + - ansible_distribution_release == "jammy" + + - name: Change Python link Ubuntu Jammy + command: ln -sf /usr/bin/python3.9 /usr/bin/python3 + when: + - ansible_pkg_mgr == "apt" + - ansible_distribution == "Ubuntu" + - ansible_distribution_release == "jammy" + + - name: Change Python link Ubuntu Xenial + command: ln -sf /usr/local/bin/python3.8 /usr/bin/python3 + when: + - ansible_pkg_mgr == "apt" + - ansible_distribution == "Ubuntu" + - ansible_distribution_release == "xenial" + + # --------------------------------------------------------------------- + # Pip installation ---------------------------------------------------- + + - stat: + path: /usr/bin/pip3 + register: stat_pip3 + when: + - ansible_pkg_mgr == "apt" + + - name: Install pip Ubuntu\Debian + shell: curl https://bootstrap.pypa.io/get-pip.py | python3 - + when: + - ansible_pkg_mgr == "apt" + - stat_pip3.stat.exists == False + - ansible_distribution_release != "xenial" + - ansible_distribution_release != "focal" + - ansible_distribution_release != "bionic" + + - name: Install pip Ubuntu Xenial + shell: curl https://bootstrap.pypa.io/get-pip.py | python3 - + when: + - ansible_pkg_mgr == "apt" + - stat_pip3.stat.exists == False + - ansible_distribution_release == "xenial" + + when: + - install_python is defined + - install_python == true + + # No version specified in pyyaml due to Xenial error. + - name: Install pytest + command: pip3 install {{ item }} + with_items: "{{ pip_deps }}" + when: + - install_pip_deps is defined + - install_pip_deps == true + + - name: Clone installation assistant git repository + git: + repo: "{{ repository }}" + dest: "{{ tmp_path }}" + version: "{{ packages_reference }}" + depth: 1 + force: true + + - name: Generate unattended + command: "bash {{ tmp_path }}/unattended_installer/builder.sh -i -d" + + - name: Change pre-release repository to selected one + command: "sed -i 's|pre-release|{{ pkg_repository }}|g' {{ script_name }}" + args: + chdir: "{{ script_path }}" + + - name: Change wazuh rpm revision to generic one + command: "sed -i 's|wazuh_revision_rpm=.*|wazuh_revision_rpm=\"*\"|g' {{ script_name }}" + args: + chdir: "{{ script_path }}" + + - name: Change wazuh deb revision to generic one + command: "sed -i 's|wazuh_revision_deb=.*|wazuh_revision_deb=\"*\"|g' {{ script_name }}" + args: + chdir: "{{ script_path }}" + + - name: Change indexer rpm revision to generic one + command: "sed -i 's|indexer_revision_rpm=.*|indexer_revision_rpm=\"*\"|g' {{ script_name }}" + args: + chdir: "{{ script_path }}" + + - name: Change indexer deb revision to generic one + command: "sed -i 's|indexer_revision_deb=.*|indexer_revision_deb=\"*\"|g' {{ script_name }}" + args: + chdir: "{{ script_path }}" + + - name: Change dashboard rpm revision to generic one + command: "sed -i 's|dashboard_revision_rpm=.*|dashboard_revision_rpm=\"*\"|g' {{ script_name }}" + args: + chdir: "{{ script_path }}" + + - name: Change dashboard deb revision to generic one + command: "sed -i 's|dashboard_revision_deb=.*|dashboard_revision_deb=\"*\"|g' {{ script_name }}" + args: + chdir: "{{ script_path }}" \ No newline at end of file