Monday, February 21, 2022

[SOLVED] Puppet not getting saved with Packer on CentOS 7.1

Issue

I am trying to create a Vagrant box using Packer, and everything works fine until I try to install Puppet in the Packer box. The Packer logs clearly says that Puppet is getting installed correctly. However, when I load up the box in Vagrant and SSH into it, Puppet is nowhere to be found (tested this with yum list | grep puppet). When I issue the commands that Packer's supposed to execute when creating the box directly on the Vagrant box and run my test command again, Puppet is in fact getting listed there.

I have already tried to rearrange the order of the scripts in the shell provision, but none of this helped at all. The commands to Puppet do seem to be working (seeing that I could get it working directly in the Vagrant box).

I have created a gist with all of my files. I am installing it on CentOS 7.1.


Solution

First things I'd say:

  • make sure to cleanup at the really end (run cleanup.sh after puppet.sh)
  • yum list <package> will list all available packages (and installed packages), to know which packages are installed you should run yum list installed (you might have an issue in your repos or mirrors if you do not get any output at all from your command)
  • as you installed from rpm, you can also run rpm -qa | grep puppet to find out if the package has been installed, you should get something like (depending the version)

    [vagrant@vagrant ~]$ rpm -qa | grep puppet
    puppetlabs-release-6-11.noarch
    

From a quick view, the script looks good - I do install from the following script

install_puppet()
{
    echo "==> Installing Puppet"
    REDHAT_MAJOR_VERSION=$(egrep -Eo 'release ([0-9][0-9.]*)' /etc/redhat-release | cut -f2 -d' ' | cut -f1 -d.)

    echo "==> Installing Puppet Labs repositories"
    rpm -ipv "http://yum.puppetlabs.com/puppetlabs-release-el-${REDHAT_MAJOR_VERSION}.noarch.rpm"

    if [[ ${CM_VERSION:-} == 'latest' ]]; then
        echo "==> Installing latest Puppet version"
        yum -y install puppet
    else
        echo "==> Installing Puppet version ${CM_VERSION}"
        yum -y install "puppet-${CM_VERSION}"
    fi
}

so it does basically the same -

Update

Its very strange, I created a box from your gist and the box was okay - puppet was installed.

I only changed from puppet.sh

#!/bin/sh
#rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm 
rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm 
yum -y install puppet

so I was able to install puppet 3.x rather than puppet 4.x - and I used an existing Vagrantfile with simple provisioning and all was ok

When I vagrant up the VM, provisioning for puppet was running and packaged installed.



Answered By - Frederic Henri
Answer Checked By - Marilyn (WPSolving Volunteer)