封隔器建造中的流浪汉配置

时间:2015-12-27 13:46:51

标签: linux ubuntu vagrant packer

我想用Packer创建一个Vagrant盒子。为此我在github上使用了一个打包器项目:Packer ubuntu 14.04 LTS

实际上,'packer build'命令运行正常,我可以正常使用我的流浪盒。但是我希望使用我的配置和工具预安装来构建一个Vagrant框。

为此,我创建了一个新的脚本sh文件,该文件在供应者脚本包装器模板中运行。

#!/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

并包含此文件:

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

所有打包程序构建都正确运行且没有错误。但是当用这个盒子创建我的Vagrant并启动一个cd / etc / apache2它就找不到了。没有安装apache2。

因为当我在我的流浪汉上手动运行这个命令'apt-get -y install apache2'时,它会返回给我

  

无法打开文件锁/ var / lib / dpkg / lock - 打开(13:不允许权限)   无法锁定管理目录(/ var / lib / dpkg /)。你有超级用户权限吗?

我认为有这个问题,因为用于配置我的流浪者的流浪者用户没有这个权利。但我无法理解为什么,因为我已经有了这个:

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

vagrant.sh脚本:

  "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"
    }
  ]
template.json打包器中的

构建器:

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

和我的preseed.cfg ubuntu:

vagrant up

您能否告诉我如何在我的配置器构建中使用sudo访问权限或root用户?我希望管理我的流浪盒之前全力以赴。

操作系统主机:Windows 7专业版 OS Guest:Ubuntu 14.04 LTS VM技术:VirtualBox 5.0.10 + Vagrant 1.7.4 VM工具构建器:Packer 0.8.6

编辑

我的调试日志告诉我apache已正确安装并重启...

但是当utf8_general_ci utf8_unicode_ci utf8mb4_general_ci utf8mb4_unicode_ci 我认为那个参数

  

config.vm.box_url

运行不正确,因为当找到不存在的文件时,它正确地启动了一个虚拟框。

在这种情况下,我认为流浪汉没有好的盒子,我没有在我的流浪汉安装我的apache

1 个答案:

答案 0 :(得分:1)

执行以下操作:

#vagrant box list

删除所有或不需要的框:

#vagrant box remove <box>

使用新方框运行vagrant:

#vagrant up --provision

或者只是在没有配置的情况下启动该框:

#vagrant up --no-provision

最后:

#vagrant ssh