Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked the OVA workflow,creation process and upgraded base OS #170

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
aacf955
ova workflow redesing wip
CarlosALgit Jan 16, 2025
ad73973
some changes in the playbook and adding of the python script file
CarlosALgit Jan 16, 2025
704a5e8
created and developed the python script
CarlosALgit Jan 17, 2025
17410b0
latests changes to the workflow
CarlosALgit Jan 20, 2025
a4561fb
added amazon linux 2023 composite name
CarlosALgit Jan 20, 2025
1eae0e0
added allocator path to the env
CarlosALgit Jan 20, 2025
d4a8463
added port to ssh connection
CarlosALgit Jan 20, 2025
e951f8b
added private key file to the ssh connection
CarlosALgit Jan 20, 2025
f479393
changed inventory path
CarlosALgit Jan 20, 2025
728f76f
added installation of aws collection
CarlosALgit Jan 21, 2025
3700620
fixed command in ansible playbook
CarlosALgit Jan 21, 2025
c6b50f0
deleted libraries tasks in the playbook
CarlosALgit Jan 21, 2025
8414930
removed python3 installation in the aws instance
CarlosALgit Jan 21, 2025
3e9e8fb
changed virtualbox and vagrant installation commands and added become…
CarlosALgit Jan 21, 2025
42e5c25
changed tpm for tmp typho
CarlosALgit Jan 21, 2025
baf0d1c
installed dependencies for virtualbox installation
CarlosALgit Jan 21, 2025
d88ae30
separated dependencies in new lines
CarlosALgit Jan 21, 2025
bde34ea
changed tasks to move to the repository and checkout to the branch ev…
CarlosALgit Jan 21, 2025
c8ea638
changed the thypo from workflow_scripts to workflow_assets
CarlosALgit Jan 21, 2025
09bb124
add show output task when creating the base box and fixing scp command
CarlosALgit Jan 21, 2025
f329085
added async and waiters to some tasks
CarlosALgit Jan 21, 2025
589655c
removed task for logs
CarlosALgit Jan 21, 2025
5f2d8d1
added ignore errors when creating the base vagrant box
CarlosALgit Jan 21, 2025
8c9ad25
deleted missconfiguration in the generate base box script
CarlosALgit Jan 21, 2025
2116226
added retries in the vagrant up task
CarlosALgit Jan 21, 2025
858c8c6
updated workflow to update the allocator directory to gh
CarlosALgit Jan 22, 2025
386f72b
added task to destroy previous machines
CarlosALgit Jan 22, 2025
b9b53e2
added become to both tasks
CarlosALgit Jan 22, 2025
88e1966
change vagrant up command and added debug task
CarlosALgit Jan 22, 2025
ad1f974
add task to copy the python script to the vm
CarlosALgit Jan 22, 2025
5bb4c4c
added more retries to vagrant up and an echo debug
CarlosALgit Jan 22, 2025
e284255
added block task
CarlosALgit Jan 22, 2025
050e1df
redesing vagrant up task
CarlosALgit Jan 22, 2025
8388b47
added ignore error when vagrant up to see logs
CarlosALgit Jan 22, 2025
43161df
added async
CarlosALgit Jan 22, 2025
a2252a8
fixed scp command
CarlosALgit Jan 22, 2025
6c8a68c
added change of the wvm repository
CarlosALgit Jan 23, 2025
c66c4b0
added async to the export ova task
CarlosALgit Jan 23, 2025
ba62cd8
commented dev or prod in the provision.sh
CarlosALgit Jan 23, 2025
3d49271
added private key file to the scp task
CarlosALgit Jan 23, 2025
5989503
added permissions to the exported ova file
CarlosALgit Jan 23, 2025
23b57c0
raised the retries for the vagrant up task
CarlosALgit Jan 23, 2025
ad38612
last changes to the ova workflow files deleting comments and changing…
CarlosALgit Jan 23, 2025
d99d5e9
fixed clone of the wazuh-installation-assistant repo
CarlosALgit Jan 23, 2025
25294e6
fix clone of wazuh-installation-assistant repo
CarlosALgit Jan 23, 2025
34f3ae7
fixed destroy of the aws instance
CarlosALgit Jan 23, 2025
e269fbd
Merge branch '4.11.0' into bug/147-upgrade-the-ova-base-os-and-the-bu…
CarlosALgit Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 188 additions & 75 deletions .github/workflows/ansible_playbooks/ova_generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,208 @@
become: true

tasks:
- name: Update all the packages
yum:
name: '*'
state: latest

- name: Install pip
yum:
name: python3-pip
state: present

- name: Download VirtualBox installer script
get_url:
url: https://download.virtualbox.org/virtualbox/7.1.4/VirtualBox-7.1.4-165100-Linux_amd64.run
dest: /tmp/VirtualBox.run

- name: Make the installer script executable
file:
path: /tmp/VirtualBox.run
mode: '0755'

- name: Install required packages for building kernel modules
yum:
name:
- kernel-devel
- kernel-headers
- dkms
- elfutils-libelf-devel
- gcc
- make
- perl
state: present
become: true

- name: Run VirtualBox installer script
command: bash /tmp/VirtualBox.run
become: true

- name: Update all the packages
yum:
name: '*'
state: latest

- name: Install Development tools
command: dnf groupinstall "Development Tools" -y
become: true

- name: Rebuild the VirtualBox kernel modules
command: /sbin/vboxconfig

- name: Install utilities for Vagrant
command: yum install -y yum-utils shadow-utils

- name: Add the Vagrant repository
command: yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo

- name: Install Vagrant
command: yum -y install vagrant

- name: Install git
shell: sudo yum install -y git
shell: yum install -y git
become: true

- name: Make build directory
- name: Create directory for the base VM
file:
path: "{{ ova_path }}"
path: "/tmp/ova_directory"
state: directory
mode: '0755'

- name: Copy ova directory
copy:
src: "../../../ova"
dest: "{{ ova_path }}"

- name: Download the Wazuh installation assistant repository
- name: Download the Wazuh virtual machines repository
git:
repo: "{{ wia_repository }}"
version: "{{ wia_branch }}"
dest: '/tmp/{{ wia_scripts }}'
depth: 1
repo: "{{ wvm_repository }}"
version: "{{ wvm_branch }}"
dest: "/tmp/wazuh-virtual-machines"
register: clone_result
retries: 6
delay: 10
until: clone_result is success

- name: Set custom hostname
command: "hostnamectl set-hostname wazuh-server"

- name: Build Wazuh installation assistant script
command: "bash /tmp/{{ wia_scripts }}/builder.sh {{ builder_args }}"

- name: Copy Wazuh installation assistant script to tmp dir
command: "cp /tmp/{{ wia_scripts }}/wazuh-install.sh /tmp/wazuh-install.sh"

- name: Run provision script
command: "bash provision.sh {{ repository }} {{ debug }}"
- name: Create base box
shell: "./generate_base_box.sh"
args:
chdir: "{{ ova_path }}/ova"
async: 3600
poll: 10

- name: Clean provision files
file:
path: /var/provision/
state: absent

- name: Clean Wazuh installation assistant resources
file:
path: /tmp/{{ wia_scripts }}
state: absent

- name: Clean Wazuh installation assistant script
file:
path: /tmp/wazuh-install.sh
state: absent

- name: Clean Wazuh installation assistant files
file:
path: /tmp/wazuh-install-files.tar
state: absent
chdir: "/tmp/wazuh-virtual-machines/ova/workflow_assets"
register: base_box_creation_result
async: 1800
poll: 0
ignore_errors: yes

- name: Wait for the base box creation to finish
async_status:
jid: "{{ base_box_creation_result.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 30
delay: 60

- name: Add the created box
shell: "vagrant box add --name al2023 /tmp/wazuh-virtual-machines/ova/workflow_assets/al2023.box"

- name: Destroy previous machines
shell: |
#!/bin/bash
cd /tmp/wazuh-virtual-machines/ova/workflow_assets
machines=$(vagrant global-status --prune | awk '/running|saved|poweroff/ {print $1}')
if [ -n "$machines" ]; then
for id in $machines; do
vagrant destroy -f $id
done
fi
args:
executable: /bin/bash
register: vagrant_up_result
become: true

- name: Clean logs
- name: Run vagrant up
shell: |
find /var/log/ -type f -exec bash -c 'cat /dev/null > {}' \;
find /var/ossec/logs -type f -execdir sh -c 'cat /dev/null > "$1"' _ {} \;
find /var/log/wazuh-indexer -type f -execdir sh -c 'cat /dev/null > "$1"' _ {} \;
find /var/log/filebeat -type f -execdir sh -c 'cat /dev/null > "$1"' _ {} \;
rm -rf /var/log/wazuh-install.log
#!/bin/bash
MAX_RETRIES=100
attempts=0
cd /tmp/wazuh-virtual-machines/ova/workflow_assets
while true; do
((attempts++))
echo "Attempt $attempts"
if vagrant up; then
break
else
if [ $attempts -eq $MAX_RETRIES ]; then
echo "Max attempts reached"
exit 1
fi
vagrant destroy -f
fi
done
args:
executable: /bin/bash
async: 7200
poll: 0
register: vagrant_up_result
become: true

- name: Wait for vagrant up to finish
async_status:
jid: "{{ vagrant_up_result.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 120
delay: 60

- name: Show the result of the vagrant up command
debug:
var: vagrant_up_result
verbosity: 2

- name: Copy the Python script to the VM
shell: |
cd /tmp/wazuh-virtual-machines/ova/workflow_assets
vagrant plugin install vagrant-scp
vagrant scp ova_configurer.py :/tmp/ova_configurer.py
args:
chdir: "/tmp/wazuh-virtual-machines/ova/workflow_assets"
become: true

- name: Clean history
shell: cat /dev/null > ~/.bash_history && history -c
- name: Execute Python script in the VM
shell: "vagrant ssh -c 'sudo python3 /tmp/ova_configurer.py --wia_branch {{ wia_branch }} --wvm_branch {{ wvm_branch }} --repository {{ repository }} --debug {{ debug}}'"
args:
chdir: "/tmp/wazuh-virtual-machines/ova/workflow_assets"
register: python_script_result
async: 1800
poll: 0

- name: Wait for the Python script to finish
async_status:
jid: "{{ python_script_result.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 30
delay: 60

- name: Stop the VM
shell: "vagrant halt"
args:
chdir: "/tmp/wazuh-virtual-machines/ova/workflow_assets"

- name: Clean YUM cache
- name: Configure VM network in VirtualBox
shell: |
yum clean all
rm -rf /var/cache/yum/*

- name: Remove AuthorizedKeysCommand from sshd_config
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?AuthorizedKeysCommand.*'
state: absent

- name: Remove AuthorizedKeysCommandUser from sshd_config
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?AuthorizedKeysCommandUser.*'
state: absent

- name: Restart SSH service
service:
name: sshd
state: restarted
vboxmanage modifyvm ova_base --nic2 hostonly
vboxmanage modifyvm ova_base --cableconnected2 on

- name: Export the VM to OVA
shell: "vboxmanage export ova_base --output /home/ec2-user/{{ filename_ova }}"
register: export_result
async: 1800
poll: 0

- name: Wait for export the OVA
async_status:
jid: "{{ export_result.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 30
delay: 60

- name: Change permissions to the OVA file
file:
path: /home/ec2-user/{{ filename_ova }}
mode: '0755'
Loading
Loading