diff --git a/group_vars/all/vars.yml b/group_vars/all/vars.yml index db7c381..5556ce2 100644 --- a/group_vars/all/vars.yml +++ b/group_vars/all/vars.yml @@ -18,22 +18,25 @@ defaultBaserootfs: "therealbobo/ubuntu-rootfs:23.04" # name: the name given to the vm; # kernel: reference to an OCI image containing a kernel; # rootfs: reference to an OCI image used as base rootfs for the vm. +# arch: architecture of the kernel and base images. (x86_64/aarch64). machines: - - {name: "arch-5.18",kernel: "therealbobo/arch-kernel:5.18", rootfs: "therealbobo/arch-image:5.18"} - - {name: "arch-6.0",kernel: "therealbobo/arch-kernel:6.0", rootfs: "therealbobo/arch-image:6.0"} - - {name: "fedora-38",kernel: "therealbobo/fedora-kernel:38-6.2.9", rootfs: "therealbobo/fedora-image:38-6.2.9"} - - {name: "fedora-36",kernel: "therealbobo/fedora-kernel:36-5.17.5", rootfs: "therealbobo/fedora-image:36-5.17.5"} - - {name: "fedora-33",kernel: "therealbobo/fedora-kernel:33-5.8.15", rootfs: "therealbobo/fedora-image:33-5.8.15"} - - {name: "ubuntu-23.04-6.3.0",kernel: "therealbobo/ubuntu-kernel:23.04-6.3.0", rootfs: "therealbobo/ubuntu-image:23.04-6.3.0"} - - {name: "centos-4.18",kernel: "therealbobo/centos-kernel:4.18", rootfs: "therealbobo/centos-image:4.18"} - - {name: "centos-5.14",kernel: "therealbobo/centos-kernel:5.14", rootfs: "therealbobo/centos-image:5.14"} - - {name: "amz-linux-2023-6.1.34",kernel: "therealbobo/amazonlinux2023-kernel:6.1.34", rootfs: "therealbobo/amazonlinux2023-image:6.1.34"} - - {name: "amz-linux-2022-5.15.73",kernel: "therealbobo/amazonlinux2022-kernel:5.15.73", rootfs: "therealbobo/amazonlinux2022-image:5.15.73"} - - {name: "amz-linux2-4.19",kernel: "therealbobo/amazonlinux2-kernel:4.19", rootfs: "therealbobo/amazonlinux2-image:4.19"} - - {name: "amz-linux2-5.4",kernel: "therealbobo/amazonlinux2-kernel:5.4", rootfs: "therealbobo/amazonlinux2-image:5.4"} - - {name: "amz-linux2-5.15",kernel: "therealbobo/amazonlinux2-kernel:5.15", rootfs: "therealbobo/amazonlinux2-image:5.15"} - - {name: "oracle-linux-5.15",kernel: "therealbobo/oraclelinux-kernel:5.15", rootfs: "therealbobo/oraclelinux-image:5.15"} - - {name: "oracle-linux-5.4",kernel: "therealbobo/oraclelinux-kernel:5.4", rootfs: "therealbobo/oraclelinux-image:5.4"} + - {name: "arch-5.18",kernel: "therealbobo/arch-kernel:5.18", rootfs: "therealbobo/arch-image:5.18", arch: "x86_64"} + - {name: "arch-6.0",kernel: "therealbobo/arch-kernel:6.0", rootfs: "therealbobo/arch-image:6.0", arch: "x86_64"} + - {name: "fedora-38",kernel: "therealbobo/fedora-kernel:38-6.2.9", rootfs: "therealbobo/fedora-image:38-6.2.9", arch: "x86_64"} + - {name: "fedora-36",kernel: "therealbobo/fedora-kernel:36-5.17.5", rootfs: "therealbobo/fedora-image:36-5.17.5", arch: "x86_64"} + - {name: "fedora-33",kernel: "therealbobo/fedora-kernel:33-5.8.15", rootfs: "therealbobo/fedora-image:33-5.8.15", arch: "x86_64"} + - {name: "ubuntu-23.04-6.3.0",kernel: "therealbobo/ubuntu-kernel:23.04-6.3.0", rootfs: "therealbobo/ubuntu-image:23.04-6.3.0", arch: "x86_64"} + - {name: "centos-4.18",kernel: "therealbobo/centos-kernel:4.18", rootfs: "therealbobo/centos-image:4.18", arch: "x86_64"} + - {name: "centos-5.14",kernel: "therealbobo/centos-kernel:5.14", rootfs: "therealbobo/centos-image:5.14", arch: "x86_64"} + - {name: "amz-linux-2023-6.1.34",kernel: "therealbobo/amazonlinux2023-kernel:6.1.34", rootfs: "therealbobo/amazonlinux2023-image:6.1.34", arch: "x86_64"} + - {name: "amz-linux-2022-5.15.73",kernel: "therealbobo/amazonlinux2022-kernel:5.15.73", rootfs: "therealbobo/amazonlinux2022-image:5.15.73", arch: "x86_64"} + - {name: "amz-linux2-4.19",kernel: "therealbobo/amazonlinux2-kernel:4.19", rootfs: "therealbobo/amazonlinux2-image:4.19", arch: "x86_64"} + - {name: "amz-linux2-5.4",kernel: "therealbobo/amazonlinux2-kernel:5.4", rootfs: "therealbobo/amazonlinux2-image:5.4", arch: "x86_64"} + - {name: "amz-linux2-5.15",kernel: "therealbobo/amazonlinux2-kernel:5.15", rootfs: "therealbobo/amazonlinux2-image:5.15", arch: "x86_64"} + - {name: "oracle-linux-5.15",kernel: "therealbobo/oraclelinux-kernel:5.15", rootfs: "therealbobo/oraclelinux-image:5.15", arch: "x86_64"} + - {name: "oracle-linux-5.4",kernel: "therealbobo/oraclelinux-kernel:5.4", rootfs: "therealbobo/oraclelinux-image:5.4", arch: "x86_64"} + - {name: "amazonlinux-5.4", kernel: "therealbobo/amazonlinux2-kernel:5.4-arm64", rootfs: "therealbobo/amazonlinux2-image:5.4-arm64", arch: "aarch64"} + - {name: "oraclelinux-5.15", kernel: "therealbobo/oraclelinux-kernel:5.15-arm64", rootfs: "therealbobo/oraclelinux-image:5.15-arm64", arch: "aarch64"} # Kernel that does not support running execve with null argv: `https://github.com/torvalds/linux/commit/dcd46d897adb70d63e025f175a00a89797d31a43` # We need to disable the tests calling the execve syscall. @@ -54,6 +57,9 @@ cpus: 2 # Memory size in GB. memory: 2 +# run_id is used to identify all the machines generated by a given run of the playbook. +run_id: "here-goes-the-id" + ##################### # SSH configuration # ##################### diff --git a/roles/bootstrap/tasks/main.yml b/roles/bootstrap/tasks/main.yml index c3672e6..4ca5ce1 100644 --- a/roles/bootstrap/tasks/main.yml +++ b/roles/bootstrap/tasks/main.yml @@ -29,6 +29,8 @@ dest: "./roles/bootstrap/files/{{ item.name }}.yaml" loop: "{{ machines }}" + when: item.arch == ansible_facts["architecture"] + delegate_to: localhost - name: Pull kernel and rootfs OCI images @@ -38,37 +40,42 @@ name: "{{ item.kernel }}" source: pull loop: "{{ machines }}" + when: item.arch == ansible_facts["architecture"] - name: Pull rootfs OCI images community.docker.docker_image: name: "{{ item.rootfs }}" source: pull loop: "{{ machines }}" + when: item.arch == ansible_facts["architecture"] -- name: Create virtual machines +- name: Create virtual machines run_id={{ run_id }} shell: | ignite run --config "./roles/bootstrap/files/{{ item.name }}.yaml" --runtime docker loop: "{{ machines }}" + when: item.arch == ansible_facts["architecture"] become: yes -- name: Wait for the VMs to be running +- name: Wait for the VMs to be running run_id={{ run_id }} shell: - cmd: ignite ps -f \{\{.ObjectMeta.Name\}\}={{item.name}},\{\{.Status.Running\}\}=true | wc -l + cmd: ignite ps -f \{\{.ObjectMeta.Name\}\}={{item.name}}-{{ run_id }},\{\{.Status.Running\}\}=true | wc -l register: result until: result.stdout | int == 2 retries: 5 delay: 10 become: yes loop: "{{ machines }}" + when: item.arch == ansible_facts["architecture"] -- name: Get IP of the VMs and register them in a variable +- name: Get IP of the VMs and register them in a variable run_id={{ run_id }} shell: - cmd: ignite ps -f \{\{.ObjectMeta.Name\}\}={{ item.name }},\{\{.Status.Running\}\}=true -t \{\{.Status.Network.IPAddresses\}\} + cmd: ignite ps -f \{\{.ObjectMeta.Name\}\}={{ item.name }}-{{ run_id }},\{\{.Status.Running\}\}=true -t \{\{.Status.Network.IPAddresses\}\} register: machineIps become: yes failed_when: machineIps.stdout_lines | length != 1 loop: "{{ machines }}" - + when: item.arch == ansible_facts["architecture"] + - name: Template the inventory.ini.j2 configuration file to invetory.ini template: src: inventory.ini.j2 diff --git a/roles/bootstrap/templates/ignite-vm.yaml.j2 b/roles/bootstrap/templates/ignite-vm.yaml.j2 index 20d3678..f5a48ae 100644 --- a/roles/bootstrap/templates/ignite-vm.yaml.j2 +++ b/roles/bootstrap/templates/ignite-vm.yaml.j2 @@ -2,7 +2,9 @@ apiVersion: ignite.weave.works/v1alpha4 kind: VM metadata: # Required, the name of the VM - name: {{ item.name }} + name: {{ item.name }}-{{ run_id}} + labels: + run: {{ run_id }} spec: # Optional, how many vCPUs should be allocated for the VM # Default: 1 diff --git a/roles/bootstrap/templates/inventory.ini.j2 b/roles/bootstrap/templates/inventory.ini.j2 index fdac19b..2366ee9 100644 --- a/roles/bootstrap/templates/inventory.ini.j2 +++ b/roles/bootstrap/templates/inventory.ini.j2 @@ -1,5 +1,7 @@ #this file is autogenerated by the bootstrap role [machines] {% for result in machineIps.results %} +{% if "skipped" not in result %} {{ result.item.name }} ansible_host={{ result.stdout }} ansible_ssh_private_key_file={{ prv_key_path }} +{% endif%} {% endfor %} diff --git a/roles/clean-up/tasks/main.yml b/roles/clean-up/tasks/main.yml index 16acabc..0303c29 100644 --- a/roles/clean-up/tasks/main.yml +++ b/roles/clean-up/tasks/main.yml @@ -14,24 +14,31 @@ state: absent with_items: "{{ files_to_delete.files }}" -- name: Get name of vms and register them in variables - shell: - cmd: ignite ps --all -f \{\{.ObjectMeta.Name\}\}={{item.name}} -t \{\{.Name\}\} - register: vms - become: yes - loop: "{{ machines }}" -- name: Stop machines - shell: - cmd: ignite kill {{item.1}} - become: yes - loop: "{{ vms.results|subelements('stdout_lines') }}" +# We search all the machines created for this run_id. +# We make sure that all machines are stopped and then delete them. +- name: Stop running machines and delete them + block: + - name: Get name of running machines run_id={{ run_id }} + shell: + cmd: ignite ps --all -f \{\{.Labels.run\}\}={{ run_id }},\{\{.Status.Running\}\}=true -t \{\{.Name\}\} + register: vms + + - name: Stop running machines run_id={{ run_id }} + shell: + cmd: ignite kill {{item}} + loop: "{{ vms.stdout_lines }}" -- name: Delete machines - shell: - cmd: ignite rm {{item.1}} - become: yes - loop: "{{ vms.results|subelements('stdout_lines') }}" + - name: Get name of stopped machines run_id={{ run_id }} + shell: + cmd: ignite ps --all -f \{\{.Labels.run\}\}={{ run_id }} -t \{\{.Name\}\} + register: vms + + - name: Delete machines run_id={{ run_id }} + shell: + cmd: ignite rm {{ item }} + loop: "{{ vms.stdout_lines }}" + become: true # Ignite imports the images from the OCI ones and caches them. # If the images change in the remote repository, ignite continues to use @@ -41,7 +48,7 @@ block: - name: List cached images shell: - cmd: ignite image ls -q + cmd: ignite images ls | tail +2 | cut -f 1 register: images - name: Remove cached images from ignite @@ -51,7 +58,7 @@ - name: List cached kernels shell: - cmd: ignite kernel ls -q + cmd: ignite kernel ls | tail +2 | cut -f 1 register: kernels - name: Remove cached kernels from ignite