From ec903e2a0e7880dfc90d1618d1485439b64379db Mon Sep 17 00:00:00 2001 From: Eugene Zamriy Date: Fri, 7 Jul 2023 12:57:32 +0300 Subject: [PATCH] Adds VirtualBox Vagrant box build configuration Also added the "upgrade_and_reboot" role that upgrades all packages and reboots a VM if something has been upgraded. --- .gitignore | 1 + README.md | 6 +++++ ansible/requirements.yml | 3 ++- ansible/roles/upgrade_and_reboot/README.md | 13 +++++++++ .../upgrade_and_reboot/defaults/main.yml | 5 ++++ .../roles/upgrade_and_reboot/meta/main.yml | 19 +++++++++++++ .../roles/upgrade_and_reboot/tasks/main.yml | 14 ++++++++++ ansible/vagrant.yml | 3 +++ msvsphere-9-vagrant.pkr.hcl | 27 +++++++++++++++++++ 9 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/upgrade_and_reboot/README.md create mode 100644 ansible/roles/upgrade_and_reboot/defaults/main.yml create mode 100644 ansible/roles/upgrade_and_reboot/meta/main.yml create mode 100644 ansible/roles/upgrade_and_reboot/tasks/main.yml diff --git a/.gitignore b/.gitignore index c1f236d..2762d6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode *.box +ansible/roles/ezamriy.vbox_guest diff --git a/README.md b/README.md index 610ca9e..0ddc286 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,12 @@ variables. ### Building Vagrant boxes +VirtualBox Vagrant box build command: + +```shell +$ packer build -only=virtualbox-iso.msvsphere-9-vagrant-x86_64 . +``` + VMWare Vagrant box build command: ```shell diff --git a/ansible/requirements.yml b/ansible/requirements.yml index 7d35793..6585815 100644 --- a/ansible/requirements.yml +++ b/ansible/requirements.yml @@ -1,3 +1,4 @@ --- collections: [] -roles: [] +roles: + - name: ezamriy.vbox_guest diff --git a/ansible/roles/upgrade_and_reboot/README.md b/ansible/roles/upgrade_and_reboot/README.md new file mode 100644 index 0000000..02b65f0 --- /dev/null +++ b/ansible/roles/upgrade_and_reboot/README.md @@ -0,0 +1,13 @@ +# upgrade_and_reboot + +An Ansible role that upgrades all packages to their latest versions and +reboots a host. + + +## Role Variables + +Role variables and their default values are listed below: + +* `reboot_connect_timeout: 5` - number of seconds to sleep before retrying check. +* `reboot_timeout: 600` - maximum number of seconds to wait for a host return. +* `reboot_post_reboot_delay: 15` - number of seconds to wait before starting checking. diff --git a/ansible/roles/upgrade_and_reboot/defaults/main.yml b/ansible/roles/upgrade_and_reboot/defaults/main.yml new file mode 100644 index 0000000..a35435a --- /dev/null +++ b/ansible/roles/upgrade_and_reboot/defaults/main.yml @@ -0,0 +1,5 @@ +--- +reboot_connect_timeout: 5 +reboot_pre_reboot_delay: 60 +reboot_post_reboot_delay: 60 +reboot_timeout: 600 diff --git a/ansible/roles/upgrade_and_reboot/meta/main.yml b/ansible/roles/upgrade_and_reboot/meta/main.yml new file mode 100644 index 0000000..17fc009 --- /dev/null +++ b/ansible/roles/upgrade_and_reboot/meta/main.yml @@ -0,0 +1,19 @@ +galaxy_info: + role_name: upgrade_and_reboot + author: Eugene Zamriy + description: Upgrades all packages, reboots a host and waits for it to return + license: MIT + + min_ansible_version: '2.7' + + platforms: + - name: EL + versions: + - '8' + - '9' + + galaxy_tags: + - reboot + - upgrade + +dependencies: [] diff --git a/ansible/roles/upgrade_and_reboot/tasks/main.yml b/ansible/roles/upgrade_and_reboot/tasks/main.yml new file mode 100644 index 0000000..047762a --- /dev/null +++ b/ansible/roles/upgrade_and_reboot/tasks/main.yml @@ -0,0 +1,14 @@ +--- +- name: Upgrade packages + ansible.builtin.dnf: + name: '*' + state: latest + register: system_upgrade + +- name: Reboot host + ansible.builtin.reboot: + connect_timeout: "{{ reboot_connect_timeout }}" + pre_reboot_delay: "{{ reboot_pre_reboot_delay }}" + post_reboot_delay: "{{ reboot_post_reboot_delay }}" + reboot_timeout: "{{ reboot_timeout }}" + when: system_upgrade.changed diff --git a/ansible/vagrant.yml b/ansible/vagrant.yml index b83423b..de6ecd9 100644 --- a/ansible/vagrant.yml +++ b/ansible/vagrant.yml @@ -4,6 +4,9 @@ become: true roles: + - upgrade_and_reboot + - role: ezamriy.vbox_guest + when: packer_provider == 'virtualbox-iso' - role: vmware_guest when: packer_provider == 'vmware-iso' - nfs_client diff --git a/msvsphere-9-vagrant.pkr.hcl b/msvsphere-9-vagrant.pkr.hcl index 86089cb..0d2444e 100644 --- a/msvsphere-9-vagrant.pkr.hcl +++ b/msvsphere-9-vagrant.pkr.hcl @@ -2,6 +2,32 @@ * Packer template for building MSVSphere 9 Vagrant boxes. */ +source "virtualbox-iso" "msvsphere-9-vagrant-x86_64" { + iso_url = var.iso_url_9_x86_64 + iso_checksum = var.iso_checksum_9_x86_64 + boot_command = var.vagrant_boot_cmd_9_x86_64_bios + boot_wait = var.boot_wait + cpus = var.cpus + memory = var.memory + disk_size = var.vagrant_disk_size + headless = var.headless + http_directory = var.http_directory + guest_os_type = "RedHat_64" + shutdown_command = var.vagrant_shutdown_command + ssh_username = var.vagrant_ssh_username + ssh_password = var.vagrant_ssh_password + ssh_timeout = var.ssh_timeout + hard_drive_interface = "sata" + iso_interface = "sata" + vboxmanage = [ + ["modifyvm", "{{.Name}}", "--nat-localhostreachable1", "on"], + ] + vboxmanage_post = [ + ["modifyvm", "{{.Name}}", "--memory", var.post_memory], + ["modifyvm", "{{.Name}}", "--cpus", var.post_cpus] + ] +} + source "vmware-iso" "msvsphere-9-vagrant-x86_64" { iso_url = var.iso_url_9_x86_64 iso_checksum = var.iso_checksum_9_x86_64 @@ -30,6 +56,7 @@ source "vmware-iso" "msvsphere-9-vagrant-x86_64" { build { sources = [ + "sources.virtualbox-iso.msvsphere-9-vagrant-x86_64", "sources.vmware-iso.msvsphere-9-vagrant-x86_64" ]