Test installation assistant - System CentOS 8 - Launched by @davidcr01 #151
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run-name: Test installation assistant - System ${{ inputs.SYSTEM }} - Launched by @${{ github.actor }} | |
name: Test installation assistant | |
on: | |
pull_request: | |
paths: | |
- 'cert_tool/**' | |
- 'common_functions/**' | |
- 'config/**' | |
- 'install_functions/**' | |
- 'passwords_tool/**' | |
- 'tests/**' | |
workflow_dispatch: | |
inputs: | |
REPOSITORY: | |
description: 'Repository environment' | |
required: true | |
default: 'pre-release' | |
type: choice | |
options: | |
- staging | |
- pre-release | |
AUTOMATION_REFERENCE: | |
description: 'Branch or tag of the wazuh-automation repository' | |
required: true | |
default: '4.10.0' | |
SYSTEM: | |
description: 'Operating System' | |
required: true | |
default: 'CentOS 8' | |
type: choice | |
options: | |
- CentOS 7 | |
- CentOS 8 | |
- Amazon Linux 2 | |
- Ubuntu 16 | |
- Ubuntu 18 | |
- Ubuntu 20 | |
- Ubuntu 22 | |
- RHEL7 | |
- RHEL8 | |
VERBOSITY: | |
description: 'Verbosity level on playbooks execution' | |
required: true | |
default: '-v' | |
type: choice | |
options: | |
- -v | |
- -vv | |
- -vvv | |
- -vvvv | |
DESTROY: | |
description: 'Destroy instances after run' | |
required: true | |
default: true | |
type: boolean | |
env: | |
COMPOSITE_NAME: "linux-SUBNAME-amd64" | |
SESSION_NAME: "Installation-Assistant-Test" | |
REGION: "us-east-1" | |
TMP_PATH: "/tmp/test" | |
LOGS_PATH: "${{ github.workspace }}/assistant_logs" | |
PKG_REPOSITORY: "${{ inputs.REPOSITORY }}" | |
REFERENCE: "${{ github.ref_name }}" | |
TEST_NAME: "test_assistant" | |
REPOSITORY_URL: "${{ github.server_url }}/${{ github.repository }}.git" | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
jobs: | |
initialize-environment: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: View parameters | |
run: echo "${{ toJson(inputs) }}" | |
- name: Set COMPOSITE_NAME variable | |
run: | | |
case "${{ inputs.SYSTEM }}" in | |
"CentOS 7") | |
SUBNAME="centos-7" | |
;; | |
"CentOS 8") | |
SUBNAME="centos-8" | |
;; | |
"Amazon Linux 2") | |
SUBNAME="amazon-2" | |
;; | |
"Ubuntu 16") | |
SUBNAME="ubuntu-16.04" | |
;; | |
"Ubuntu 18") | |
SUBNAME="ubuntu-18.04" | |
;; | |
"Ubuntu 20") | |
SUBNAME="ubuntu-20.04" | |
;; | |
"Ubuntu 22") | |
SUBNAME="ubuntu-22.04" | |
;; | |
"RHEL7") | |
SUBNAME="redhat-7" | |
;; | |
"RHEL8") | |
SUBNAME="redhat-8" | |
;; | |
*) | |
echo "Invalid SYSTEM selection" >&2 | |
exit 1 | |
;; | |
esac | |
COMPOSITE_NAME="${COMPOSITE_NAME/SUBNAME/$SUBNAME}" | |
echo "COMPOSITE_NAME=$COMPOSITE_NAME" >> $GITHUB_ENV | |
- name: Install Ansible | |
run: sudo apt-get update && sudo apt install -y python3 && python3 -m pip install --user ansible-core==2.16 | |
- name: Get Ansible | |
run: ansible --version | |
- name: Set up AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_IAM_ROLE }} | |
role-session-name: ${{ env.SESSION_NAME }} | |
aws-region: ${{ env.REGION }} | |
- name: Checkout wazuh/wazuh-automation repository | |
uses: actions/checkout@v4 | |
with: | |
repository: wazuh/wazuh-automation | |
ref: ${{ inputs.AUTOMATION_REFERENCE }} | |
token: ${{ secrets.GH_CLONE_TOKEN }} | |
path: wazuh-automation | |
- name: Install and set allocator requirements | |
run: pip3 install -r wazuh-automation/deployability/deps/requirements.txt | |
- name: Allocate instance test and set SSH variables | |
id: allocator_instance | |
run: | | |
python3 wazuh-automation/deployability/modules/allocation/main.py --action create --provider aws --size large --composite-name ${{ env.COMPOSITE_NAME }} --working-dir /tmp/allocator_instance \ | |
--track-output /tmp/allocator_instance/track.yml --inventory-output /tmp/allocator_instance/inventory.yml --instance-name gha_${{ github.run_id }}_assistant_test \ | |
--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 | |
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: Execute provision.yml playbook | |
run: | | |
INSTALL_DEPS=true | |
INSTALL_PYTHON=true | |
INSTALL_PIP_DEPS=true | |
ansible-playbook .github/workflows/ansible-playbooks/provision.yml \ | |
-i /tmp/allocator_instance/inventory \ | |
-l all \ | |
-e "repository=$REPOSITORY_URL" \ | |
-e "reference=4.9.0-testing" \ | |
-e "tmp_path=$TMP_PATH" \ | |
-e "pkg_repository=$PKG_REPOSITORY" \ | |
-e "install_deps=$INSTALL_DEPS" \ | |
-e "install_python=$INSTALL_PYTHON" \ | |
-e "install_pip_deps=$INSTALL_PIP_DEPS" \ | |
"${{ inputs.VERBOSITY }}" | |
- name: Execute AIO installation playbook | |
run: | | |
ansible-playbook .github/workflows/ansible-playbooks/aio.yml \ | |
-i /tmp/allocator_instance/inventory \ | |
-l all \ | |
-e "tmp_path=$TMP_PATH" \ | |
-e "logs_path=$LOGS_PATH" \ | |
-e "test_name=$TEST_NAME" \ | |
"${{ inputs.VERBOSITY }}" | |
- name: Execute Python test playbook | |
run: | | |
TEST_NAME="test_installation_assistant" | |
ansible-playbook .github/workflows/ansible-playbooks/aio_tests.yml \ | |
-i /tmp/allocator_instance/inventory \ | |
-l all \ | |
-e "tmp_path=$TMP_PATH" \ | |
-e "logs_path=$LOGS_PATH" \ | |
-e "test_name=$TEST_NAME" \ | |
"${{ inputs.VERBOSITY }}" | |
- name: Delete allocated VM | |
if: always() && steps.allocator_instance.outcome == 'success' && inputs.DESTROY == true | |
run: python3 wazuh-automation/deployability/modules/allocation/main.py --action delete --track-output /tmp/allocator_instance/track.yml | |