当我创建一个vagrant virtualbox packer box时,我有一个非常奇怪的行为。在将它们部署到生产环境之前,我正在使用带有vagrant的盒子来测试我的puppet模块。我想在ubuntu-16.04上为puppet5服务器使用puppet-agent。您可以在下面的日志文件中看到PACKER_LOG=1 packer build ubuntu-16.04.json
的输出,但是当我登录到vagrant框时,我只有puppet 3.8.x
和puppet-common
而没有puppet-agent
的跟踪。
我删除了旧盒子,创建了一个新的流浪者,以确保我使用当前的盒子,但不幸的是我无法解决这个问题。
所以要么我在框内做apt-get update && apt-get install puppet-agent
,要么我用带有shell配置器的vagrant安装它,但我想用packer来管理它。
以下是日志输出的相关部分:
==> virtualbox-iso: Provisioning with shell script: scripts/puppet.sh
2018/05/07 05:59:27 ui: ==> virtualbox-iso: Provisioning with shell script: scripts/puppet.sh
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 Opening scripts/puppet.sh for reading
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [INFO] 181 bytes written for 'uploadData'
2018/05/07 05:59:27 [INFO] 181 bytes written for 'uploadData'
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] Opening new ssh session
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] Starting remote scp process: scp -vt /tmp
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] Started SCP session, beginning transfers...
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] scp: Uploading script_8159.sh: perms=C0644 size=181
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] SCP session complete, closing stdin pipe.
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] Waiting for SSH session to complete.
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] scp stderr (length 31): Sink: C0644 181 script_8159.sh
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] Opening new ssh session
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] starting remote command: chmod 0755 /tmp/script_8159.sh
2018/05/07 05:59:27 [INFO] RPC client: Communicator ended with: 0
2018/05/07 05:59:27 [INFO] RPC endpoint: Communicator ended with: 0
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [INFO] RPC endpoint: Communicator ended with: 0
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [INFO] RPC client: Communicator ended with: 0
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] Opening new ssh session
2018/05/07 05:59:27 packer: 2018/05/07 05:59:27 [DEBUG] starting remote command: echo 'vagrant' | PACKER_BUILDER_TYPE='virtualbox-iso' PACKER_BUILD_NAME='virtualbox-iso' PACKER_HTTP_ADDR='10.0.2.2:8421' sudo -E -S bash '/tmp/script_8159.sh'
2018/05/07 05:59:27 ui: virtualbox-iso: --2018-05-07 05:59:27-- https://apt.puppetlabs.com/puppet5-release-xenial.deb
virtualbox-iso: --2018-05-07 05:59:27-- https://apt.puppetlabs.com/puppet5-release-xenial.deb
2018/05/07 05:59:28 ui: virtualbox-iso: Resolving apt.puppetlabs.com (apt.puppetlabs.com)... 52.85.173.69, 52.85.173.15, 52.85.173.19, ...
virtualbox-iso: Resolving apt.puppetlabs.com (apt.puppetlabs.com)... 52.85.173.69, 52.85.173.15, 52.85.173.19, ...
virtualbox-iso: Connecting to apt.puppetlabs.com (apt.puppetlabs.com)|52.85.173.69|:443... connected.
2018/05/07 05:59:28 ui: virtualbox-iso: Connecting to apt.puppetlabs.com (apt.puppetlabs.com)|52.85.173.69|:443... connected.
2018/05/07 05:59:28 ui: virtualbox-iso: HTTP request sent, awaiting response... 200 OK
virtualbox-iso: HTTP request sent, awaiting response... 200 OK
virtualbox-iso: Length: 6850 (6.7K) [application/x-debian-package]
2018/05/07 05:59:28 ui: virtualbox-iso: Length: 6850 (6.7K) [application/x-debian-package]
virtualbox-iso: Saving to: ‘puppet5-release-xenial.deb’
2018/05/07 05:59:28 ui: virtualbox-iso: Saving to: ‘puppet5-release-xenial.deb’
virtualbox-iso:
2018/05/07 05:59:28 ui: virtualbox-iso:
virtualbox-iso: 0K ...... 100% 29.0M=0s
2018/05/07 05:59:28 ui: virtualbox-iso: 0K ...... 100% 29.0M=0s
virtualbox-iso:
2018/05/07 05:59:28 ui: virtualbox-iso:
2018/05/07 05:59:28 ui: virtualbox-iso: 2018-05-07 05:59:28 (29.0 MB/s) - ‘puppet5-release-xenial.deb’ saved [6850/6850]
virtualbox-iso: 2018-05-07 05:59:28 (29.0 MB/s) - ‘puppet5-release-xenial.deb’ saved [6850/6850]
virtualbox-iso:
2018/05/07 05:59:28 ui: virtualbox-iso:
virtualbox-iso: Selecting previously unselected package puppet5-release.
2018/05/07 05:59:28 ui: virtualbox-iso: Selecting previously unselected package puppet5-release.
virtualbox-iso: (Reading database ... 64089 files and directories currently installed.)
2018/05/07 05:59:28 ui: virtualbox-iso: (Reading database ... 64089 files and directories currently installed.)
2018/05/07 05:59:28 ui: virtualbox-iso: Preparing to unpack puppet5-release-xenial.deb ...
virtualbox-iso: Preparing to unpack puppet5-release-xenial.deb ...
virtualbox-iso: Unpacking puppet5-release (5.0.0-1xenial) ...
2018/05/07 05:59:28 ui: virtualbox-iso: Unpacking puppet5-release (5.0.0-1xenial) ...
2018/05/07 05:59:28 ui: virtualbox-iso: Setting up puppet5-release (5.0.0-1xenial) ...
virtualbox-iso: Setting up puppet5-release (5.0.0-1xenial) ...
virtualbox-iso: Ign:1 http://apt.puppetlabs.com xenial InRelease
2018/05/07 05:59:29 ui: virtualbox-iso: Ign:1 http://apt.puppetlabs.com xenial InRelease
virtualbox-iso: Get:2 http://apt.puppetlabs.com xenial Release [57.5 kB]
2018/05/07 05:59:29 ui: virtualbox-iso: Get:2 http://apt.puppetlabs.com xenial Release [57.5 kB]
2018/05/07 05:59:29 ui: virtualbox-iso: Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease
virtualbox-iso: Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease
2018/05/07 05:59:29 ui: virtualbox-iso: Hit:4 http://de.archive.ubuntu.com/ubuntu xenial InRelease
virtualbox-iso: Hit:4 http://de.archive.ubuntu.com/ubuntu xenial InRelease
virtualbox-iso: Get:5 http://apt.puppetlabs.com xenial Release.gpg [836 B]
2018/05/07 05:59:29 ui: virtualbox-iso: Get:5 http://apt.puppetlabs.com xenial Release.gpg [836 B]
virtualbox-iso: Hit:6 http://de.archive.ubuntu.com/ubuntu xenial-updates InRelease
2018/05/07 05:59:29 ui: virtualbox-iso: Hit:6 http://de.archive.ubuntu.com/ubuntu xenial-updates InRelease
2018/05/07 05:59:29 ui: virtualbox-iso: Hit:7 http://de.archive.ubuntu.com/ubuntu xenial-backports InRelease
virtualbox-iso: Hit:7 http://de.archive.ubuntu.com/ubuntu xenial-backports InRelease
virtualbox-iso: Get:8 http://apt.puppetlabs.com xenial/puppet5 amd64 Packages [15.5 kB]
2018/05/07 05:59:30 ui: virtualbox-iso: Get:8 http://apt.puppetlabs.com xenial/puppet5 amd64 Packages [15.5 kB]
virtualbox-iso: Get:9 http://apt.puppetlabs.com xenial/puppet5 i386 Packages [13.4 kB]
2018/05/07 05:59:30 ui: virtualbox-iso: Get:9 http://apt.puppetlabs.com xenial/puppet5 i386 Packages [13.4 kB]
virtualbox-iso: Get:10 http://apt.puppetlabs.com xenial/puppet5 all Packages [7,432 B]
2018/05/07 05:59:30 ui: virtualbox-iso: Get:10 http://apt.puppetlabs.com xenial/puppet5 all Packages [7,432 B]
2018/05/07 05:59:31 ui: virtualbox-iso: Fetched 94.6 kB in 1s (51.7 kB/s)
virtualbox-iso: Fetched 94.6 kB in 1s (51.7 kB/s)
2018/05/07 05:59:33 ui: virtualbox-iso: Reading package lists...
virtualbox-iso: Reading package lists...
virtualbox-iso: Reading package lists...
2018/05/07 05:59:34 ui: virtualbox-iso: Reading package lists...
2018/05/07 05:59:34 ui: virtualbox-iso: Building dependency tree...
virtualbox-iso: Building dependency tree...
2018/05/07 05:59:34 ui: virtualbox-iso: Reading state information...
virtualbox-iso: Reading state information...
2018/05/07 05:59:34 ui: virtualbox-iso: The following NEW packages will be installed:
virtualbox-iso: The following NEW packages will be installed:
2018/05/07 05:59:34 ui: virtualbox-iso: puppet-agent
virtualbox-iso: puppet-agent
2018/05/07 05:59:35 ui: virtualbox-iso: 0 upgraded, 1 newly installed, 0 to remove and 44 not upgraded.
virtualbox-iso: 0 upgraded, 1 newly installed, 0 to remove and 44 not upgraded.
2018/05/07 05:59:35 ui: virtualbox-iso: Need to get 17.2 MB of archives.
virtualbox-iso: Need to get 17.2 MB of archives.
2018/05/07 05:59:35 ui: virtualbox-iso: After this operation, 96.1 MB of additional disk space will be used.
virtualbox-iso: After this operation, 96.1 MB of additional disk space will be used.
2018/05/07 05:59:35 ui: virtualbox-iso: Get:1 http://apt.puppetlabs.com xenial/puppet5 amd64 puppet-agent amd64 5.5.1-1xenial [17.2 MB]
virtualbox-iso: Get:1 http://apt.puppetlabs.com xenial/puppet5 amd64 puppet-agent amd64 5.5.1-1xenial [17.2 MB]
virtualbox-iso: debconf: unable to initialize frontend: Dialog
2018/05/07 05:59:42 ui: virtualbox-iso: debconf: unable to initialize frontend: Dialog
2018/05/07 05:59:42 ui: virtualbox-iso: debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.)
virtualbox-iso: debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.)
virtualbox-iso: debconf: falling back to frontend: Readline
2018/05/07 05:59:42 ui: virtualbox-iso: debconf: falling back to frontend: Readline
2018/05/07 05:59:42 ui: virtualbox-iso: debconf: unable to initialize frontend: Readline
virtualbox-iso: debconf: unable to initialize frontend: Readline
virtualbox-iso: debconf: (This frontend requires a controlling tty.)
2018/05/07 05:59:42 ui: virtualbox-iso: debconf: (This frontend requires a controlling tty.)
2018/05/07 05:59:42 ui: virtualbox-iso: debconf: falling back to frontend: Teletype
virtualbox-iso: debconf: falling back to frontend: Teletype
2018/05/07 05:59:42 ui: virtualbox-iso: dpkg-preconfigure: unable to re-open stdin:
virtualbox-iso: dpkg-preconfigure: unable to re-open stdin:
2018/05/07 05:59:43 ui: virtualbox-iso: Fetched 17.2 MB in 7s (2,295 kB/s)
virtualbox-iso: Fetched 17.2 MB in 7s (2,295 kB/s)
2018/05/07 05:59:43 ui: virtualbox-iso: Selecting previously unselected package puppet-agent.
virtualbox-iso: Selecting previously unselected package puppet-agent.
2018/05/07 05:59:43 ui: virtualbox-iso: (Reading database ... 64094 files and directories currently installed.)
virtualbox-iso: (Reading database ... 64094 files and directories currently installed.)
2018/05/07 05:59:43 ui: virtualbox-iso: Preparing to unpack .../puppet-agent_5.5.1-1xenial_amd64.deb ...
virtualbox-iso: Preparing to unpack .../puppet-agent_5.5.1-1xenial_amd64.deb ...
2018/05/07 05:59:43 ui: virtualbox-iso: Unpacking puppet-agent (5.5.1-1xenial) ...
virtualbox-iso: Unpacking puppet-agent (5.5.1-1xenial) ...
virtualbox-iso: Processing triggers for libc-bin (2.23-0ubuntu10) ...
2018/05/07 06:00:19 ui: virtualbox-iso: Processing triggers for libc-bin (2.23-0ubuntu10) ...
virtualbox-iso: Setting up puppet-agent (5.5.1-1xenial) ...
2018/05/07 06:00:19 ui: virtualbox-iso: Setting up puppet-agent (5.5.1-1xenial) ...
2018/05/07 06:00:20 ui: virtualbox-iso: Created symlink from /etc/systemd/system/multi-user.target.wants/puppet.service to /lib/systemd/system/puppet.service.
virtualbox-iso: Created symlink from /etc/systemd/system/multi-user.target.wants/puppet.service to /lib/systemd/system/puppet.service.
virtualbox-iso: Created symlink from /etc/systemd/system/multi-user.target.wants/mcollective.service to /lib/systemd/system/mcollective.service.
2018/05/07 06:00:20 ui: virtualbox-iso: Created symlink from /etc/systemd/system/multi-user.target.wants/mcollective.service to /lib/systemd/system/mcollective.service.
virtualbox-iso: Created symlink from /etc/systemd/system/multi-user.target.wants/pxp-agent.service to /lib/systemd/system/pxp-agent.service.
2018/05/07 06:00:20 ui: virtualbox-iso: Created symlink from /etc/systemd/system/multi-user.target.wants/pxp-agent.service to /lib/systemd/system/pxp-agent.service.
2018/05/07 06:00:21 ui: virtualbox-iso: Removed symlink /etc/systemd/system/multi-user.target.wants/pxp-agent.service.
virtualbox-iso: Removed symlink /etc/systemd/system/multi-user.target.wants/pxp-agent.service.
2018/05/07 06:00:21 ui: virtualbox-iso: Processing triggers for libc-bin (2.23-0ubuntu10) ...
virtualbox-iso: Processing triggers for libc-bin (2.23-0ubuntu10) ...
virtualbox-iso: Reading package lists...
2018/05/07 06:00:22 ui: virtualbox-iso: Reading package lists...
virtualbox-iso: Building dependency tree...
2018/05/07 06:00:22 ui: virtualbox-iso: Building dependency tree...
2018/05/07 06:00:22 ui: virtualbox-iso: Reading state information...
virtualbox-iso: Reading state information...
virtualbox-iso: 0 upgraded, 0 newly installed, 0 to remove and 44 not upgraded.
2018/05/07 06:00:22 ui: virtualbox-iso: 0 upgraded, 0 newly installed, 0 to remove and 44 not upgraded.
2018/05/07 06:00:22 [INFO] 2950 bytes written for 'stdout'
2018/05/07 06:00:22 [INFO] 971 bytes written for 'stderr'
2018/05/07 06:00:22 [INFO] RPC client: Communicator ended with: 0
2018/05/07 06:00:22 [INFO] RPC endpoint: Communicator ended with: 0
2018/05/07 06:00:22 packer: 2018/05/07 06:00:22 [INFO] RPC endpoint: Communicator ended with: 0
2018/05/07 06:00:22 packer: 2018/05/07 06:00:22 [INFO] 2950 bytes written for 'stdout'
2018/05/07 06:00:22 packer: 2018/05/07 06:00:22 [INFO] 971 bytes written for 'stderr'
2018/05/07 06:00:22 packer: 2018/05/07 06:00:22 [INFO] RPC client: Communicator ended with: 0
2018/05/07 06:00:22 packer: 2018/05/07 06:00:22 [DEBUG] Opening new ssh session
2018/05/07 06:00:22 packer: 2018/05/07 06:00:22 [DEBUG] starting remote command: rm -f /tmp/script_8159.sh
2018/05/07 06:00:23 packer: 2018/05/07 06:00:23 [INFO] RPC endpoint: Communicator ended with: 0
2018/05/07 06:00:23 [INFO] RPC client: Communicator ended with: 0
2018/05/07 06:00:23 [INFO] RPC endpoint: Communicator ended with: 0
2018/05/07 06:00:23 packer: 2018/05/07 06:00:23 [INFO] RPC client: Communicator ended with: 0
==> virtualbox-iso: Provisioning with shell script: scripts/cleanup.sh
这是我的json文件:
{
"variables": {
"vm_name": "ubuntu-16.04",
"disk_size": "40960",
"http_directory": "http",
"hostname": "vagrant",
"ssh_fullname": "vagrant",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_wait_timeout": "10000s",
"iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.4-server-amd64.iso",
"iso_checksum_url": "http://releases.ubuntu.com/16.04/SHA256SUMS",
"iso_checksum_type": "sha256",
"preseed" : "preseed.cfg"
},
"builders": [{
"type": "virtualbox-iso",
"headless": true,
"boot_wait": "10s",
"disk_size": "{{user `disk_size`}}",
"http_directory": "http",
"guest_os_type": "Ubuntu_64",
"iso_url": "{{user `iso_url`}}",
"iso_checksum_url": "{{user `iso_checksum_url`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ssh_password": "{{user `ssh_password`}}",
"ssh_wait_timeout": "{{user `ssh_wait_timeout`}}",
"shutdown_command": "echo '{{user `ssh_password`}}' | sudo -S shutdown -P now",
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"virtualbox_version_file": ".vbox_version",
"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--cpus", "2" ],
[ "modifyvm", "{{.Name}}", "--memory", "1024" ],
[ "modifyvm", "{{.Name}}", "--nictype1", "virtio" ],
[ "modifyvm", "{{.Name}}", "--natdnsproxy1", "on" ],
[ "modifyvm", "{{.Name}}", "--natdnshostresolver1", "on" ]
],
"boot_command": [
"<enter><wait>",
"<f6><esc>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs>",
"/install/vmlinuz noapic ",
"initrd=/install/initrd.gz ",
"auto preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed.cfg ",
"auto-install/enable=true ",
"debconf/frontend=noninteractive<wait> ",
"debian-installer={{ user `locale` }} auto locale={{ user `locale` }} kbd-chooser/method=de ",
"fb=false debconf/frontend=noninteractive ",
"console-setup/ask_detect=false ",
"keyboard-configuration/modelcode=pc105 ",
"keyboard-configuration/layout=DE ",
"keyboard-configuration/variant=DE ",
"hostname={{user `hostname`}} ",
"passwd/user-fullname={{ user `ssh_fullname` }} ",
"passwd/user-password={{ user `ssh_password` }} ",
"passwd/user-password-again={{ user `ssh_password` }} ",
"passwd/username={{ user `ssh_username` }} ",
"-- <wait>",
"<enter>"
]
}],
"provisioners": [
{
"type": "shell",
"pause_before": "30s",
"execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -E -S bash '{{.Path}}'",
"scripts": [
"scripts/network.sh",
"scripts/config.sh",
"scripts/vagrant.sh",
"scripts/virtualbox.sh",
"scripts/puppet.sh",
"scripts/cleanup.sh"
]
}
],
"post-processors": [
{
"type": "vagrant",
"override": {
"virtualbox": {
"output": "ubuntu-16-04-vagrant-vbox.box"
}
}
}
]
}
这就是我使用puppet-agent
安装scripts/puppet.sh
的方式:
#!/bin/bash -eux
wget https://apt.puppetlabs.com/puppet5-release-xenial.deb
dpkg -i puppet5-release-xenial.deb
apt-get update
apt-get install puppet-agent -y
gem install r10k
如果您需要其他脚本和preseed.cfg
文件的内容,我也会发布它们。
谢谢你的帮助。
答案 0 :(得分:0)
对于任何有类似问题的人来说,解决方案很简单,我不知道为什么我在第一时间没有考虑过这个问题。要做的步骤:
#vagrant box list
这将列出流浪汉正在使用的所有盒子,由于我的经验,流浪者总是第一个,除非你指定它应该使用的盒子。然后,您可以使用以下命令删除所有或不需要的框:
#vagrant box remove <box>
感谢@Matt对此进行了研究。
干杯