feat(packer): Migrate AWS images 02/37202/1
authorpmikus <peter.mikus@protonmail.ch>
Wed, 21 Sep 2022 10:36:29 +0000 (12:36 +0200)
committerpmikus <peter.mikus@protonmail.ch>
Wed, 21 Sep 2022 10:36:29 +0000 (12:36 +0200)
Signed-off-by: pmikus <peter.mikus@protonmail.ch>
Change-Id: Ia1940e18b60e38ba559f0ebf1a8d72a4d18cebdb

fdio.infra.ansible/roles/aws/tasks/main.yaml
fdio.infra.ansible/roles/aws/tasks/ubuntu_focal.yaml [deleted file]
fdio.infra.ansible/roles/aws/tasks/ubuntu_jammy.yaml
fdio.infra.packer/aws_c5n/ubuntu_jammy.pkr.hcl [new file with mode: 0644]
fdio.infra.terraform/terraform-aws-2n-aws-c5n/variables.tf

index 2b8c22c..321f2f6 100644 (file)
@@ -7,7 +7,7 @@
     - aws-edit-repo
 
 - name: Get vfio-pci With WC Patcher
     - aws-edit-repo
 
 - name: Get vfio-pci With WC Patcher
-  get_url:
+  ansible.builtin.get_url:
     url: "https://github.com/amzn/amzn-drivers/raw/master/userspace/dpdk/enav2-vfio-patch/get-vfio-with-wc.sh"
     dest: "/opt/get-vfio-with-wc.sh"
     mode: "744"
     url: "https://github.com/amzn/amzn-drivers/raw/master/userspace/dpdk/enav2-vfio-patch/get-vfio-with-wc.sh"
     dest: "/opt/get-vfio-with-wc.sh"
     mode: "744"
     - aws-vfio-patch
 
 - name: Create vfio-pci Patch Directory
     - aws-vfio-patch
 
 - name: Create vfio-pci Patch Directory
-  file:
+  ansible.builtin.file:
     path: "/opt/patches/"
     state: "directory"
   tags:
     - aws-vfio-patch
 
     path: "/opt/patches/"
     state: "directory"
   tags:
     - aws-vfio-patch
 
-- name: Get vfio-pci WC Patch >=4.10
-  get_url:
-    url: "https://github.com/amzn/amzn-drivers/raw/master/userspace/dpdk/enav2-vfio-patch/patches/linux-4.10-vfio-wc.patch"
-    dest: "/opt/patches/linux-4.10-vfio-wc.patch"
+- name: Get vfio-pci WC Patch >=5.15
+  ansible.builtin.get_url:
+    url: "https://github.com/amzn/amzn-drivers/raw/master/userspace/dpdk/enav2-vfio-patch/patches/linux-5.15-vfio-wc.patch"
+    dest: "/opt/patches/linux-5.15-vfio-wc.patch"
     mode: "744"
   tags:
     - aws-vfio-patch
 
     mode: "744"
   tags:
     - aws-vfio-patch
 
-- name: Get vfio-pci WC Patch >=5.8
-  get_url:
-    url: "https://github.com/amzn/amzn-drivers/raw/master/userspace/dpdk/enav2-vfio-patch/patches/linux-5.8-vfio-wc.patch"
-    dest: "/opt/patches/linux-5.8-vfio-wc.patch"
-    mode: "744"
+- name: Patch WC Patch Script
+  ansible.builtin.lineinfile:
+    path: "/opt/get-vfio-with-wc.sh"
+    regexp: '^ rm -f linux-'
+    line: "    rm -f linux-*.dsc linux-*.gz linux-*.xz"
   tags:
     - aws-vfio-patch
 
   tags:
     - aws-vfio-patch
 
-- name: Compile vfio-pci With WC Patch
-  shell: "/bin/bash /opt/get-vfio-with-wc.sh"
+- name: Patch WC Patch Script II
+  ansible.builtin.replace:
+    path: "/opt/get-vfio-with-wc.sh"
+    regexp: 'linux-image-'
+    replace: 'linux-image-unsigned-'
   tags:
     - aws-vfio-patch
 
   tags:
     - aws-vfio-patch
 
+#- name: Compile vfio-pci With WC Patch
+#  ansible.builtin.shell: "/bin/bash /opt/get-vfio-with-wc.sh"
+#  environment:
+#    DEBIAN_FRONTEND: "noninteractive"
+#    TERM: "vt100"
+#  tags:
+#    - aws-vfio-patch
+
 - name: Load Kernel Modules By Default
 - name: Load Kernel Modules By Default
-  lineinfile:
+  ansible.builtin.lineinfile:
     path: "/etc/modules"
     state: "present"
     line: "{{ item }}"
     path: "/etc/modules"
     state: "present"
     line: "{{ item }}"
@@ -54,7 +65,7 @@
     - aws-load-kernel-modules
 
 - name: Add Kernel Modules Options (igb_uio)
     - aws-load-kernel-modules
 
 - name: Add Kernel Modules Options (igb_uio)
-  lineinfile:
+  ansible.builtin.lineinfile:
     path: "/etc/modprobe.d/igb_uio.conf"
     state: "present"
     line: "{{ item }}"
     path: "/etc/modprobe.d/igb_uio.conf"
     state: "present"
     line: "{{ item }}"
@@ -65,7 +76,7 @@
     - aws-load-kernel-modules
 
 - name: Add Kernel Modules Options (vfio-pci)
     - aws-load-kernel-modules
 
 - name: Add Kernel Modules Options (vfio-pci)
-  lineinfile:
+  ansible.builtin.lineinfile:
     path: "/etc/modprobe.d/vfio-noiommu.conf"
     state: "present"
     line: "{{ item }}"
     path: "/etc/modprobe.d/vfio-noiommu.conf"
     state: "present"
     line: "{{ item }}"
     - aws-load-kernel-modules
 
 - name: Reload systemd-modules
     - aws-load-kernel-modules
 
 - name: Reload systemd-modules
-  systemd:
+  ansible.builtin.systemd:
     name: "systemd-modules-load"
     state: "restarted"
   tags:
     - aws-reload-systemd-modules
 
 - name: Adjust nr_hugepages
     name: "systemd-modules-load"
     state: "restarted"
   tags:
     - aws-reload-systemd-modules
 
 - name: Adjust nr_hugepages
-  sysctl:
+  ansible.builtin.sysctl:
     name: "vm.nr_hugepages"
     value: "8192"
     state: "present"
     name: "vm.nr_hugepages"
     value: "8192"
     state: "present"
     - aws-set-hugepages
 
 - name: Shutdown host with delay
     - aws-set-hugepages
 
 - name: Shutdown host with delay
-  command: "/sbin/shutdown -P +720"
+  ansible.builtin.command: "/sbin/shutdown -P +720"
   tags:
     - aws-set-self-terminate
   tags:
     - aws-set-self-terminate
diff --git a/fdio.infra.ansible/roles/aws/tasks/ubuntu_focal.yaml b/fdio.infra.ansible/roles/aws/tasks/ubuntu_focal.yaml
deleted file mode 100644 (file)
index 60302f2..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
----
-# file: roles/aws/tasks/ubuntu_focal.yaml.yaml
-
-- name: Enable deb-src APT Repository
-  apt_repository:
-    repo: "deb-src http://archive.ubuntu.com/ubuntu focal main"
-    state: "present"
-    update_cache: true
-  tags:
-    - aws-enable-src-repo
index 4ee1545..28e8524 100644 (file)
@@ -1,8 +1,8 @@
 ---
 ---
-# file: roles/aws/tasks/ubuntu_jammy.yaml.yaml
+# file: roles/aws/tasks/ubuntu_jammy.yaml
 
 - name: Enable deb-src APT Repository
 
 - name: Enable deb-src APT Repository
-  apt_repository:
+  ansible.builtin.apt_repository:
     repo: "deb-src http://archive.ubuntu.com/ubuntu jammy main"
     state: "present"
     update_cache: true
     repo: "deb-src http://archive.ubuntu.com/ubuntu jammy main"
     state: "present"
     update_cache: true
diff --git a/fdio.infra.packer/aws_c5n/ubuntu_jammy.pkr.hcl b/fdio.infra.packer/aws_c5n/ubuntu_jammy.pkr.hcl
new file mode 100644 (file)
index 0000000..e21782f
--- /dev/null
@@ -0,0 +1,128 @@
+packer {
+  required_plugins {
+    amazon = {
+      version = ">= 1.0.1"
+      source  = "github.com/hashicorp/amazon"
+    }
+  }
+}
+
+variable "first_run_commands" {
+  description = "Commands to run before deployment via remote-exec"
+  type        = list(string)
+  default = [
+    ""
+  ]
+}
+
+variable "last_run_commands" {
+  description = "Commands to run after deployment via remote-exec"
+  type        = list(string)
+  default = [
+    "sudo sed -i 's/Unattended-Upgrade \"1\"/Unattended-Upgrade \"0\"/g' /etc/apt/apt.conf.d/20auto-upgrades"
+  ]
+}
+
+variable "ansible_file_path" {
+  description = "Path to Ansible playbook"
+  type        = string
+  default     = "../../fdio.infra.ansible/site.yaml"
+}
+
+variable "ansible_python_executable" {
+  description = "Path to Python interpreter"
+  type        = string
+  default     = "/usr/bin/python3"
+}
+
+variable "ansible_topology_path" {
+  description = "Path to Ansible playbook which creates a topology file"
+  type        = string
+  default     = "../../fdio.infra.ansible/cloud_topology.yaml"
+}
+
+variable "ansible_provision_pwd" {
+  description = "Password used for ansible provisioning (ansible_ssh_pass)"
+  type        = string
+  default     = "Csit1234"
+}
+
+source "amazon-ebs" "csit_c5n_ubuntu_jammy_sut" {
+  ami_name        = "csit_c5n_ubuntu_jammy_sut"
+  ami_description = "CSIT SUT image based on Ubuntu Jammy"
+  ena_support     = true
+  instance_type   = "c5n.4xlarge"
+  launch_block_device_mappings {
+    device_name = "/dev/sda1"
+    volume_size = 40
+    volume_type = "gp2"
+  }
+  force_deregister = true
+  region           = "eu-central-1"
+  skip_create_ami  = false
+  source_ami       = "ami-065deacbcaac64cf2"
+  ssh_username     = "ubuntu"
+}
+
+source "amazon-ebs" "csit_c5n_ubuntu_jammy_tg" {
+  ami_name        = "csit_c5n_ubuntu_jammy_tg"
+  ami_description = "CSIT TG image based on Ubuntu Jammy"
+  ena_support     = true
+  instance_type   = "c5n.4xlarge"
+  launch_block_device_mappings {
+    device_name = "/dev/sda1"
+    volume_size = 40
+    volume_type = "gp2"
+  }
+  force_deregister = true
+  region           = "eu-central-1"
+  skip_create_ami  = false
+  source_ami       = "ami-065deacbcaac64cf2"
+  ssh_username     = "ubuntu"
+}
+
+build {
+  name = "csit_c5n_ubuntu_jammy_sut-packer"
+  sources = [
+    "source.amazon-ebs.csit_c5n_ubuntu_jammy_sut"
+  ]
+  provisioner "shell" {
+    inline = var.first_run_commands
+  }
+  provisioner "ansible" {
+    playbook_file = var.ansible_file_path
+    user          = "ubuntu"
+    groups        = ["sut_aws"]
+    extra_arguments = [
+      "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
+      "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
+      "--extra-vars", "aws=true"
+    ]
+  }
+  provisioner "shell" {
+    inline = var.last_run_commands
+  }
+}
+
+build {
+  name = "csit_c5n_ubuntu_jammy_tg-packer"
+  sources = [
+    "source.amazon-ebs.csit_c5n_ubuntu_jammy_tg"
+  ]
+  provisioner "shell" {
+    inline = var.first_run_commands
+  }
+  provisioner "ansible" {
+    playbook_file = var.ansible_file_path
+    user          = "ubuntu"
+    groups        = ["tg_aws"]
+    extra_arguments = [
+      "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
+      "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
+      "--extra-vars", "aws=true"
+    ]
+  }
+  provisioner "shell" {
+    inline = var.last_run_commands
+  }
+}
index e2ec8aa..e809feb 100644 (file)
@@ -50,7 +50,7 @@ variable "placement_group_strategy" {
 variable "tg_ami" {
   description = "AMI to use for the instance."
   type        = string
 variable "tg_ami" {
   description = "AMI to use for the instance."
   type        = string
-  default     = "ami-01d1d62914ef00b25"
+  default     = "ami-0c8a3d7a52942c322"
 }
 
 variable "tg_associate_public_ip_address" {
 }
 
 variable "tg_associate_public_ip_address" {
@@ -86,7 +86,7 @@ variable "tg_source_dest_check" {
 variable "sut1_ami" {
   description = "AMI to use for the instance."
   type        = string
 variable "sut1_ami" {
   description = "AMI to use for the instance."
   type        = string
-  default     = "ami-0bfdf32a014984d8a"
+  default     = "ami-0f0ea5b110cddccb1"
 }
 
 variable "sut1_associate_public_ip_address" {
 }
 
 variable "sut1_associate_public_ip_address" {