Hi Packer World, I'm building a simple centos 7.3.1611 image in packer for use by VMware Workstation/Fusion in a vagrant environment. Is there any best practices I can follow to get this to work more consistently?
What's happening is the first vagrant up I do, the network configuration fails on me. If I vagrant halt and vagrant up it works. In the first vagrant up I get the error of --- ==> service: Setting hostname... The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! # Update sysconfig sed -i 's/\(HOSTNAME=\).*/\1service/' /etc/sysconfig/network # Update DNS sed -i 's/\(DHCP_HOSTNAME=\).*/\1"service"/' /etc/sysconfig/network-scripts/ifcfg-* [... stuff deleted ...] --- Yet when I use the atlas version of centos/7, it works just fine. My packer script is fairly simple with a basic kickstart file, one script to setup the vagrant.sh. Why does the centos/7 image work and my packer based centos ISO image not work? Thanks ian -- This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list. GitHub Issues: https://github.com/mitchellh/packer/issues IRC: #packer-tool on Freenode --- You received this message because you are subscribed to the Google Groups "Packer" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/1392c07a-ebd9-48da-ad04-2fe4a63b3419%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
test.json
Description: application/json
#repo http://mirror.centos.org/centos/7/os/x86_64/ install text keyboard us lang en_US.UTF-8 skipx network --device eth0 --bootproto dhcp rootpw --plaintext vagrant user --name=vagrant --password=vagrant firewall --disabled authconfig --enableshadow --enablemd5 selinux --enforcing timezone --utc UTC # The biosdevname and ifnames options ensure we get "eth0" as our interface # even in environments like virtualbox that emulate a real NW card bootloader --location=mbr --append="no_timer_check console=tty0 console=ttyS0,115200 net.ifnames=0 biosdevname=0" zerombr clearpart --all --initlabel autopart firstboot --disabled #clearpart --all --drives=sda #part biosboot --fstype=biosboot --size=1 #part /boot --fstype xfs --size=1024 --ondisk=sda #part pv.2 --size=1 --grow --ondisk=sda #volgroup VolGroup00 --pesize=32768 pv.2 #logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=768 --grow --maxsize=1536 #logvol / --fstype xfs --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow reboot %packages # vagrant needs this to copy initial files via scp openssh-clients deltarpm bash-completion man-pages bzip2 @core rsync screen nfs-utils chrony yum-utils #hyperv-daemons # Microcode updates cannot work in a VM -microcode_ctl # Firmware packages are not needed in a VM -aic94xx-firmware -alsa-firmware -alsa-tools-firmware -ivtv-firmware -iwl100-firmware -iwl1000-firmware -iwl105-firmware -iwl135-firmware -iwl2000-firmware -iwl2030-firmware -iwl3160-firmware -iwl3945-firmware -iwl4965-firmware -iwl5000-firmware -iwl5150-firmware -iwl6000-firmware -iwl6000g2a-firmware -iwl6000g2b-firmware -iwl6050-firmware -iwl7260-firmware -iwl7265-firmware # Don't build rescue initramfs -dracut-config-rescue # Disable kdump -kexec-tools %end # kdump needs to reserve 160MB + 2bits/4kB RAM, and automatic allocation only # works on systems with at least 2GB RAM (which excludes most Vagrant boxes) # CBS doesn't support %addon yet https://bugs.centos.org/view.php?id=12169 #%addon com_redhat_kdump --disable #%end %post # sudo echo "%vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant # Fix for https://github.com/CentOS/sig-cloud-instance-build/issues/38 cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF DEVICE="eth0" BOOTPROTO="dhcp" ONBOOT="yes" TYPE="Ethernet" PERSISTENT_DHCLIENT="yes" EOF # sshd: disable password authentication and DNS checks #ex -s /etc/ssh/sshd_config <<EOF #:%substitute/^\(PasswordAuthentication\) yes$/\1 no/ #:%substitute/^#\(UseDNS\) yes$/&\r\1 no/ #:update #:quit #EOF #cat >>/etc/sysconfig/sshd <<EOF # Decrease connection time by preventing reverse DNS lookups # (see https://lists.centos.org/pipermail/centos-devel/2016-July/014981.html # and man sshd for more information) #OPTIONS="-u0" #EOF # Default insecure vagrant key #mkdir -m 0700 -p /home/vagrant/.ssh #echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" >> /home/vagrant/.ssh/authorized_keys #chmod 600 /home/vagrant/.ssh/authorized_keys #chown -R vagrant:vagrant /home/vagrant/.ssh # Fix for issue #76, regular users can gain admin privileges via su ex -s /etc/pam.d/su <<'EOF' # allow vagrant to use su, but prevent others from becoming root or vagrant /^account\s\+sufficient\s\+pam_succeed_if.so uid = 0 use_uid quiet$/ :append account [success=1 default=ignore] \\ pam_succeed_if.so user = vagrant use_uid quiet account required pam_succeed_if.so user notin root:vagrant . :update :quit EOF # systemd should generate a new machine id during the first boot, to # avoid having multiple Vagrant instances with the same id in the local # network. /etc/machine-id should be empty, but it must exist to prevent # boot errors (e.g. systemd-journald failing to start). :>/etc/machine-id echo 'vag' > /etc/yum/vars/infra # Configure grub to wait just 1 second before booting sed -i 's/^GRUB_TIMEOUT=[0-9]\+$/GRUB_TIMEOUT=1/' /etc/default/grub && grub2-mkconfig -o /boot/grub2/grub.cfg # Blacklist the floppy module to avoid probing timeouts echo blacklist floppy > /etc/modprobe.d/nofloppy.conf chcon -u system_u -r object_r -t modules_conf_t /etc/modprobe.d/nofloppy.conf # Customize the initramfs pushd /etc/dracut.conf.d # Enable VMware PVSCSI support for VMware Fusion guests. echo 'add_drivers+=" vmw_pvscsi "' > vmware-fusion-drivers.conf # There's no floppy controller, but probing for it generates timeouts echo 'omit_drivers+=" floppy "' > nofloppy.conf popd # Fix the SELinux context of the new files restorecon -f - <<EOF /etc/sudoers.d/vagrant /etc/dracut.conf.d/vmware-fusion-drivers.conf /etc/dracut.conf.d/nofloppy.conf EOF # Rerun dracut for the installed kernel (not the running kernel): KERNEL_VERSION=$(rpm -q kernel --qf '%{version}-%{release}.%{arch}\n') dracut -f /boot/initramfs-${KERNEL_VERSION}.img ${KERNEL_VERSION} # Seal for deployment rm -rf /etc/ssh/ssh_host_* hostnamectl set-hostname localhost.localdomain rm -rf /etc/udev/rules.d/70-* %end
#!/bin/bash -eux
echo '==> Configuring settings for vagrant'
SSH_USER=${SSH_USERNAME:-vagrant}
SSH_USER_HOME=${SSH_USER_HOME:-/home/${SSH_USER}}
VAGRANT_INSECURE_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
# Packer passes boolean user variables through as '1', but this might change in
# the future, so also check for 'true'.
if [ "$INSTALL_VAGRANT_KEY" = "true" ] || [ "$INSTALL_VAGRANT_KEY" = "1" ]; then
# Add vagrant user (if it doesn't already exist)
if ! id -u $SSH_USER >/dev/null 2>&1; then
echo '==> Creating ${SSH_USER}'
/usr/sbin/groupadd $SSH_USER
/usr/sbin/useradd $SSH_USER -g $SSH_USER -G wheel
echo '==> Giving ${SSH_USER} sudo powers'
echo "${SSH_USER}"|passwd --stdin $SSH_USER
echo "${SSH_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
fi
echo '==> Installing Vagrant SSH key'
mkdir -pm 700 ${SSH_USER_HOME}/.ssh
# https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
echo "${VAGRANT_INSECURE_KEY}" > $SSH_USER_HOME/.ssh/authorized_keys
chmod 0600 ${SSH_USER_HOME}/.ssh/authorized_keys
chown -R ${SSH_USER}:${SSH_USER} ${SSH_USER_HOME}/.ssh
fi
#!/bin/bash -eux echo '==> Configuring sshd_config options' echo '==> Turning off sshd DNS lookup to prevent timeout delay' echo "UseDNS no" >> /etc/ssh/sshd_config echo '==> Disablng GSSAPI authentication to prevent timeout delay' echo "GSSAPIAuthentication no" >> /etc/ssh/sshd_config
