将 vagrant 磁盘映射到 ansible 主机文件

将 vagrant 磁盘映射到 ansible 主机文件

我正在尝试在 Vagrant vm 中创建分区并将它们映射到 ansible 主机文件,但我正在运行的程序无法识别它们。

这是 Vagrantfile 配置:

Vagrant.configure("2") do |config|
  config.vm.provider :libvirt do |libvirt|
    libvirt.storage :file, :size => '20G', :device => '/dev/vdb', :bus => 'scsi'
    libvirt.storage :file, :size => '20G', :device => '/dev/vdc', :bus => 'scsi'
    libvirt.storage :file, :size => '20G', :device => '/dev/vdd', :bus => 'scsi'
    libvirt.storage :file, :size => '20G', :device => '/dev/vdf', :bus => 'scsi'
  end
  config.vm.box = "roboxes/centos9s"
  config.vm.provision "shell" do |s|
    ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
    s.inline = <<-SHELL
      echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
      echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
    SHELL
  end

以及我已配置磁盘的主机文件:

disk:
  - name: swap
    device: /dev/vdb
    partnr: 1
    label: gpt
    fstype: linux-swap
    mkfs: swap
  - name: var
    device: /dev/vdc
    partnr: 1
    label: gpt
    fstype: ext4
    mkfs: ext4
    fsopt: -m0
  - name: opt
    device: /dev/vdd
    partnr: 1
    label: gpt
    fstype: ext4
    mkfs: ext4
    fsopt: -m0

相关内容