]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-build.git/commitdiff
builder.yml: Reinstall vagrant(-libvirt) if needed 2598/head
authorDavid Galloway <david.galloway@ibm.com>
Thu, 28 May 2026 20:22:06 +0000 (16:22 -0400)
committerDavid Galloway <david.galloway@ibm.com>
Thu, 28 May 2026 20:55:04 +0000 (16:55 -0400)
Avoids:

```
Vagrant failed to properly resolve required dependencies. These
errors can commonly be caused by misconfigured plugin installations
or transient network issues. The reported error is:
nokogiri requires Ruby version >= 3.2, < 4.1.dev. The current ruby version is 2.7.4.191.
```

Which happens when an old vagrant version is installed on a builder then the version of vagrant provided in the chacra repo is newer.

Signed-off-by: David Galloway <david.galloway@ibm.com>
ansible/examples/builder.yml

index b347396ea611b5a632e7e3e1cacc916603feafea..50f922144c111c75c0ad64d97f5055737c28fc56 100644 (file)
             state: present
           when: ansible_os_family == "Debian"
 
+        - name: Check if Vagrant needs reinstall (Jammy+)
+          shell: |
+            # Strip epoch (e.g. "1:2.2.19" -> "2.2.19") before comparing, since the
+            # Ubuntu-packaged vagrant carries epoch 1 which makes apt consider it newer
+            # than the chacra package which has no epoch.
+            installed=$(dpkg-query -W -f='${Version}' vagrant 2>/dev/null | sed 's/^[0-9]*://')
+            dpkg --compare-versions "$installed" lt "2.4" && echo "yes" || echo "no"
+          register: vagrant_needs_reinstall
+          changed_when: false
+          when: ansible_os_family == "Debian" and ansible_distribution_major_version|int >= 22
+
+        # To ensure a clean vagrant-libvirt install, uninstall and reinstall vagrant.
+        - name: Purge existing Vagrant before reinstall from chacra (Jammy+)
+          apt:
+            name: vagrant
+            state: absent
+            purge: yes
+          when:
+            - ansible_os_family == "Debian"
+            - ansible_distribution_major_version|int >= 22
+            - vagrant_needs_reinstall.stdout == "yes"
+
+        - name: Install Vagrant from chacra (Jammy+)
+          apt:
+            name: vagrant
+            state: latest
+            update_cache: yes
+          when:
+            - ansible_os_family == "Debian"
+            - ansible_distribution_major_version|int >= 22
+            - vagrant_needs_reinstall.stdout == "yes"
+
+        - name: Remove stale Vagrant plugin gems after reinstall (Jammy+)
+          file:
+            path: "/home/{{ jenkins_user }}/.vagrant.d/gems"
+            state: absent
+          when:
+            - ansible_os_family == "Debian"
+            - ansible_distribution_major_version|int >= 22
+            - vagrant_needs_reinstall.stdout == "yes"
+
         - name: Add our vagrant RPM repository
           yum_repository:
             name: vagrant
             CONFIGURE_ARGS: 'with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib64'
           when: ansible_os_family == "Suse"
 
-        - name: Install the vagrant-libvirt plugin (Focal)
+        - name: Install the vagrant-libvirt plugin (Focal and newer)
           command: vagrant plugin install vagrant-libvirt
           become_user: "{{ jenkins_user }}"
           environment: