Zend certified PHP/Magento developer

GitHub Actions Vagrant+Cloud-init cannot ssh into archlinux/archlinux box for some unknown reason

Summary

I’ve posted this on StackOverFlow but was told I should delete and repost here.

I’m trying to provision this vagrant image on GitHub Actions in order to automate some testing of a software specific to this distribution, following the instructions from here on how to run vagrant in GitHub Actions..

I’ve bumped the MacOS version to macos-latest and did a test run with the original Vagrantfile being used in the GitHub repo above, the CI finished successfully.

Now, I started trying to get the CI workflow pass successfully using the ArchLinux box but it seems I can’t figure out what I need to do exactly.

I think there are 2 issues, the ssh server is probably taking more time to startup than usual and trying to provide with cloud-init doesn’t seem to work as intended (providing a password or an ssh key).


Configuration files

.github/workflow/vagrant-up.yml

name: vagrant-up

on: [push]

jobs:
  vagrant-up:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v3

        #      - name: Cache Vagrant boxes
        #        uses: actions/cache@v3
        #        with:
        #          path: ~/.vagrant.d/boxes
        #          key: ${{ runner.os }}-vagrant-${{ hashFiles('Vagrantfile') }}
        #          restore-keys: |
        #            ${{ runner.os }}-vagrant-

      - name: Show Vagrant version
        run: vagrant --version
        # Update Vagrant
        #- name: Update Vagrant
        #  run: brew install hashicorp/tap/hashicorp-vagrant
        #  run: vagrant --version

      # Attempt to fix issue connection reset, retrying...
      - name: Run vagrant plugin repair 
        run: vagrant plugin repair

      - name: Run vagrant plugin update
        run: vagrant plugin update

      - name: Run vagrant up
        run: VAGRANT_EXPERIMENTAL="cloud_init,disks" vagrant up #--debug

      - name: ssh into box after boot
        run: vagrant ssh -c "echo 'hello world!'"

cloud-init.yml

#cloud-config

users:
  - default

system_info:
   default_user:
     name: arch
     password: password
     lock_passwd: true
     gecos: arch Cloud User
     groups: [wheel, adm]
     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
     shell: /bin/bash

Vagrantfile

$own_ssh_key = <<-SCRIPT
ssh-keygen -q -t ed25519 -N "" -f .ssh/login_ssh
cp .ssh/login_ssh.pub .ssh/authorized_keys 
cp .ssh/login_ssh /vagrant/.
SCRIPT

Vagrant.configure("2") do |config|
    config.vm.box = "archlinux/archlinux"
    config.vm.cloud_init :user_data, content_type: "text/cloud-config", path: "cloud-init.yml"

    config.vm.define 'archlinux'

    config.ssh.username = "arch"
    config.ssh.password = "password"
    config.ssh.insert_key = false

    # Prevent SharedFoldersEnableSymlinksCreate errors
    config.vm.synced_folder ".", "/vagrant", disabled: true
    # Provision project.
    #config.ssh.private_key_path = [File.expand_path("../login_ssh", __FILE__)] + 
    #  Dir.glob("#{Dir.home}/.vagrant.d/boxes/archlinux/*/virtualbox/vagrant_insecure_key")

    #config.vm.provision "shell", inline: $own_ssh_key, privileged: false
end

Details & logs

I’ve tried to set config.ssh.insert_key to true or false and by commenting out the password so that vagrant uses private key authentication.

Providing a password using led to a crash of the CI with a huge Ruby stack trace, see gist

Not providing any password, and trying to let it use a default private key leads to this :

==> archlinux: Successfully added box 'archlinux/archlinux' (v20230601.155191) for 'virtualbox'!
==> archlinux: Importing base box 'archlinux/archlinux'...

Progress: 90%
==> archlinux: Matching MAC address for NAT networking...
==> archlinux: Checking if box 'archlinux/archlinux' version '20230601.155191' is up to date...
==> archlinux: Setting the name of the VM: archiso-zfs_archlinux_1685762625974_94295
==> archlinux: Clearing any previously set network interfaces...
==> archlinux: Preparing network interfaces based on configuration...
    archlinux: Adapter 1: nat
==> archlinux: Forwarding ports...
    archlinux: 22 (guest) => 2222 (host) (adapter 1)
==> archlinux: Preparing user data for cloud-init...
==> archlinux: Configuring storage mediums...
==> archlinux: Booting VM...
==> archlinux: Waiting for machine to boot. This may take a few minutes...
    archlinux: SSH address: 127.0.0.1:2222
    archlinux: SSH username: arch
    archlinux: SSH auth method: private key
    archlinux: Warning: Connection reset. Retrying...
    archlinux: Warning: Connection reset. Retrying...
    archlinux: Warning: Connection reset. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
    archlinux: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

Finally, if that can help, here are the logs of the only successfull run using the generic/ubuntu1804 vagrant image.

==> ubuntu: Matching MAC address for NAT networking...
==> ubuntu: Checking if box 'generic/ubuntu1804' version '4.2.16' is up to date...
==> ubuntu: Setting the name of the VM: archiso-zfs_ubuntu_1685757367003_57950
==> ubuntu: Clearing any previously set network interfaces...
==> ubuntu: Preparing network interfaces based on configuration...
    ubuntu: Adapter 1: nat
==> ubuntu: Forwarding ports...
    ubuntu: 22 (guest) => 2222 (host) (adapter 1)
==> ubuntu: Running 'pre-boot' VM customizations...
==> ubuntu: Booting VM...
==> ubuntu: Waiting for machine to boot. This may take a few minutes...
    ubuntu: SSH address: 127.0.0.1:2222
    ubuntu: SSH username: vagrant
    ubuntu: SSH auth method: private key
    ubuntu: 
    ubuntu: Vagrant insecure key detected. Vagrant will automatically replace
    ubuntu: this with a newly generated keypair for better security.
    ubuntu: 
    ubuntu: Inserting generated public key within guest...
    ubuntu: Removing insecure key from the guest if it's present...
    ubuntu: Key inserted! Disconnecting and reconnecting using new SSH key...
==> ubuntu: Machine booted and ready!
==> ubuntu: Checking for guest additions in VM...
    ubuntu: The guest additions on this VM do not match the installed version of
    ubuntu: VirtualBox! In most cases this is fine, but in rare cases it can
    ubuntu: prevent things such as shared folders from working properly. If you see
    ubuntu: shared folder errors, please make sure the guest additions within the
    ubuntu: virtual machine match the version of VirtualBox you have installed on
    ubuntu: your host and reload your VM.
    ubuntu: 
    ubuntu: Guest Additions Version: 5.2.42
    ubuntu: VirtualBox Version: 6.1