簡體   English   中英

Packer構建中的Vagrant Provisioning

[英]vagrant provisionning in packer build

我想用Packer創建一個Vagrant盒子。 為此,我在github上使用了一個packer項目: Packer ubuntu 14.04 LTS

由於它們是正確的,因此“ packer build”命令可以正確運行,並且我可以正常使用無業游民的盒子。 但是我想用我的配置和工具預安裝來構建一個Vagrant盒子。

為此,我創建了一個新的腳本sh文件,該文件在Provisioners腳本打包程序模板中運行。

  "provisioners": [
    {
        "execute_command": "echo 'vagrant'|sudo -S sh '{{.Path}}'",
        "override": {
            "virtualbox-iso": {
                "scripts": [
                    "scripts/base.sh",
                    "scripts/system.sh",
                    "scripts/vagrant.sh",
                    "scripts/python.sh",
                    "scripts/virtualbox.sh",
                    "scripts/docker.sh",
                    "scripts/test-perso.sh",
                    "scripts/cleanup.sh"
                ]
            }
        },
        "type": "shell"
    }
]

以及該文件的包含:

#!/bin/bash -x

apt-get -y install aptitude
apt-get -y install nano
apt-get -y install apache2
apt-get -y install php5
apt-get -y install libapache2-mod-php5

所有打包程序版本均正確運行,沒有錯誤。 但是,當使用此框創建我的Vagrant並啟動cd / etc / apache2時,找不到它。 沒有安裝apache2。

因為當我在流浪漢上手動運行此命令'apt-get -y install apache2'時,它返回我

無法打開文件鎖/ var / lib / dpkg / lock-打開(13:不允許的權限)無法鎖定管理目錄(/ var / lib / dpkg /)。 您擁有超級用戶特權嗎?

我認為有這個問題,因為用於配置我的無業游民的無業游民用戶沒有此權限。 但是我不明白為什么,因為我已經有了這個:

base.sh腳本:

# Set up sudo
echo 'vagrant ALL=NOPASSWD:ALL' > /etc/sudoers.d/vagrant

vagrant.sh腳本:

# Create the user vagrant with password vagrant
useradd -G sudo -p $(perl -e'print crypt("vagrant", "vagrant")') -m -s /bin/bash -N vagrant

# Install vagrant keys
mkdir -pm 700 /home/vagrant/.ssh
curl -Lo /home/vagrant/.ssh/authorized_keys \
  'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub'
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh

template.json packer中的構建器:

  "builders": [
    {
      "boot_command": [
        "<esc><wait>",
        "<esc><wait>",
        "<enter><wait>",
        "/install/vmlinuz<wait>",
        " auto<wait>",
        " console-setup/ask_detect=false<wait>",
        " console-setup/layoutcode=fr<wait>",
        " console-setup/modelcode=pc105<wait>",
        " debconf/frontend=noninteractive<wait>",
        " debian-installer=fr_FR<wait>",
        " fb=false<wait>",
        " initrd=/install/initrd.gz<wait>",
        " kbd-chooser/method=fr<wait>",
        " keyboard-configuration/layout=fr<wait>",
        " keyboard-configuration/variant=fr<wait>",
        " locale=fr_FR<wait>",
        " netcfg/get_domain=vm<wait>",
        " netcfg/get_hostname=vagrant<wait>",
        " noapic<wait>",
        " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
        " -- <wait>",
        "<enter><wait>"
      ],
      "boot_wait": "10s",
      "disk_size": 20480,
      "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
      "guest_os_type": "Ubuntu_64",
      "http_directory": "http",
      "headless": true,
      "iso_checksum": "0501c446929f713eb162ae2088d8dc8b6426224a",
      "iso_checksum_type": "sha1",
      "iso_url": "http://mirrors.mit.edu/ubuntu-releases/trusty/ubuntu-14.04.3-server-amd64.iso",
      "output_directory": "packer-ubuntu-14.04-amd64-virtualbox",
      "shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now",
      "ssh_username": "vagrant",
      "ssh_password": "vagrant",
      "ssh_port": 22,
      "ssh_wait_timeout": "10000s",
      "type": "virtualbox-iso",
      "vboxmanage": [
        [
          "modifyvm",
          "{{.Name}}",
          "--memory",
          "1024"
        ],
        [
          "modifyvm",
          "{{.Name}}",
          "--cpus",
          "1"
        ]
      ],
      "virtualbox_version_file": ".vbox_version",
      "vm_name": "packer-ubuntu-14.04-amd64"
    }
  ]

和我的preseed.cfg ubuntu:

choose-mirror-bin mirror/http/proxy string
d-i base-installer/kernel/override-image string linux-server
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i finish-install/reboot_in_progress note
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true
d-i passwd/user-fullname string vagrant
d-i passwd/user-uid string 900
d-i passwd/user-password password vagrant
d-i passwd/user-password-again password vagrant
d-i passwd/username string vagrant
d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common
d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select unattended-upgrades
d-i pkgsel/upgrade select full-upgrade
d-i time/zone string UTC
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
tasksel tasksel/first multiselect standard, ubuntu-server

您能告訴我如何在Packer build的Provisioning Vagrant中使用具有sudo訪問權限的用戶或root用戶嗎? 我想先全面管理我的無聊的盒子。

OS主機:Windows 7 Pro OS來賓:Ubuntu 14.04 LTS VM技術:VirtualBox 5.0.10 + Vagrant 1.7.4 VM工具生成器:Packer 0.8.6

編輯:

我的調試日志告訴我apache已正確安裝並重新啟動...

但是當一個vagrant up我認為那個參數

config.vm.box_url

無法正常運行,因為當找到不存在的文件時,它會正確地將其保存為virtualbox。

在這種情況下,我認為流浪漢不要把好盒子塞滿,而我在流浪漢中沒有安裝apache

請執行下列操作:

#vagrant box list

刪除所有或未使用的盒子:

#vagrant box remove <box>

使用新框運行流浪漢:

#vagrant up --provision

或僅在不進行配置的情況下啟動包裝盒:

#vagrant up --no-provision

最后:

#vagrant ssh

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM