由于某些未知原因,GitHub Actions Vagrant+Cloud-init 无法通过 ssh 进入 archlinux/archlinux 框

由于某些未知原因,GitHub Actions Vagrant+Cloud-init 无法通过 ssh 进入 archlinux/archlinux 框

概括

我已经在 StackOverFlow 上发布了此内容,但被告知我应该删除并在此处重新发布。

我正在尝试配置这个流浪者形象在 GitHub Actions 上,为了自动执行此发行版特有的软件测试,按照此处的说明了解如何在 GitHub Actions 中运行 vagrant。

我已将版本升级到 MacOS,macos-latest并使用上述 GitHub 存储库中的原始 Vagrantfile 进行了测试运行,CI 成功完成。

现在,我开始尝试使用 ArchLinux 框成功完成 CI 工作流程,但似乎我无法弄清楚我到底需要做什么。

我认为有两个问题,ssh 服务器可能比平时花费更多的时间来启动,并且尝试提供cloud-init似乎无法按预期工作(提供密码或 ssh 密钥)。


配置文件

.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-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

Vagrant文​​件

$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

详细信息和日志

我尝试设置config.ssh.insert_keytruefalse并通过注释掉密码以便 vagrant 使用私钥认证。

使用以下方式提供密码导致 CI​​ 崩溃,并产生巨大的 Ruby 堆栈跟踪,请参阅要点

不提供任何密码并尝试让它使用默认私钥会导致以下情况:

==> 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.

最后,如果这有帮助的话,这里是使用 vagrant 镜像唯一成功运行的日志generic/ubuntu1804

==> 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

相关内容