From 2017041f9f40799619ce577a94cd261444e15563 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Sun, 9 Jul 2017 17:58:09 +0200 Subject: [PATCH] Parameterize puppet version in install script This patch adds a global PUPPET_VERSION variable to allow changing the installed puppet version. The default version remains 3. CentOS and Ubuntu support setting it to 4. Fedora already installs 4 by default from the fedora repositories, and we defer worrying about opensuse and gentoo for now since we do not use those operating systems in the control plane and we no longer use puppet to build CI images. The script adds the new "Puppet Collections" repository and changes the name of the package to 'puppet-agent' when installing version 4. See the install guide[1] for more details. [1] https://docs.puppet.com/puppet/4.0/install_linux.html Co-authored-by: Caleb Boylan Change-Id: Id829922875d495bca9ba11a3fe3428a7ebb2cd58 --- install_puppet.sh | 71 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/install_puppet.sh b/install_puppet.sh index 0d35ecce81..decc648c4e 100755 --- a/install_puppet.sh +++ b/install_puppet.sh @@ -26,6 +26,8 @@ SETUP_PIP=${SETUP_PIP:-true} # it may not be installed yet) +PUPPET_VERSION=${PUPPET_VERSION:-3} + function is_fedora { [ -f /usr/bin/yum ] && cat /etc/*release | grep -q -e "Fedora" } @@ -131,17 +133,27 @@ function setup_puppet_fedora { } function setup_puppet_rhel7 { - local puppet_pkg="https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm" - _systemd_update yum update -y + if [ "$PUPPET_VERSION" == "3" ] ; then + puppetpkg=puppet + local puppet_repo="https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm" + elif [ "$PUPPET_VERSION" == "4" ] ; then + puppetpkg=puppet-agent + local puppet_repo="https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm" + else + echo "Unsupported puppet version ${PUPPET_VERSION}" + exit 1 + fi + # NOTE: we preinstall lsb_release to ensure facter sets lsbdistcodename yum install -y redhat-lsb-core git # Install puppetlabs repo & then puppet comes from there - rpm -ivh $puppet_pkg - yum install -y puppet + rpm -ivh $puppet_repo + + yum install -y $puppetpkg if $SETUP_PIP; then # see comments in setup_puppet_fedora @@ -158,6 +170,7 @@ function setup_puppet_rhel7 { # early for things like openvswitch (XXX: should be installed via # dib before this?) yum install -y centos-release-openstack-ocata + } function setup_puppet_ubuntu { @@ -173,10 +186,26 @@ function setup_puppet_ubuntu { rubypkg=ruby fi - - PUPPET_VERSION=3.* - PUPPETDB_VERSION=2.* - FACTER_VERSION=2.* + if [ "$PUPPET_VERSION" == "3" ] ; then + if [ $lsbdistcodename != 'xenial' ] ; then + puppet_deb=puppetlabs-release-${lsbdistcodename}.deb + else + puppet_deb='' + fi + PUPPET_VERSION=3.* + puppetpkg=puppet + PUPPETDB_VERSION=2.* + FACTER_VERSION=2.* + elif [ "$PUPPET_VERSION" == "4" ] ; then + puppet_deb=puppetlabs-release-pc1-${lsbdistcodename}.deb + puppetpkg=puppet-agent + PUPPET_VERSION=4.* + PUPPETDB_VERSION=4.* + FACTER_VERSION=3.* + else + echo "Unsupported puppet version ${PUPPET_VERSION}" + exit 1 + fi cat > /etc/apt/preferences.d/00-puppet.pref </dev/null 2>&1; then curl -O http://apt.puppetlabs.com/$puppet_deb else @@ -214,7 +243,7 @@ EOF DEBIAN_FRONTEND=noninteractive apt-get --option 'Dpkg::Options::=--force-confold' \ --assume-yes dist-upgrade DEBIAN_FRONTEND=noninteractive apt-get --option 'Dpkg::Options::=--force-confold' \ - --assume-yes install -y --force-yes puppet git $rubypkg + --assume-yes install -y --force-yes $puppetpkg git $rubypkg # Wipe out templatedir so we don't get warnings about it sed -i '/templatedir/d' /etc/puppet/puppet.conf if [ -f /bin/systemctl ]; then @@ -222,17 +251,31 @@ EOF else update-rc.d -f puppet disable fi + } function setup_puppet_opensuse { - zypper --non-interactive install --force-resolution puppet + if [ "$PUPPET_VERSION" == "3" ] ; then + puppetpkg=puppet + else + echo "Unsupported puppet version ${PUPPET_VERSION}" + exit 1 + fi + zypper --non-interactive install --force-resolution $puppetpkg # Wipe out templatedir so we don't get warnings about it sed -i '/templatedir/d' /etc/puppet/puppet.conf } function setup_puppet_gentoo { echo yes | emaint sync -a - emerge -q --jobs=4 puppet-agent + + if [ "$PUPPET_VERSION" == "3" ] ; then + puppetpkg=puppet-agent + else + echo "Unsupported puppet version ${PUPPET_VERSION}" + exit 1 + fi + emerge -q --jobs=4 $puppetpkg sed -i '/templatedir/d' /etc/puppetlabs/puppet/puppet.conf }