Skip to content

Building Puppet

aborkar-ibm edited this page May 16, 2018 · 71 revisions

Building Puppet

Below versions of Puppet are available in respective distributions at the time of creation of these build instructions:

  • SLES 11-SP4 has 2.7.26
  • Ubuntu 16.04 has 3.8.5
  • Ubuntu 17.10 has 4.10.4
  • Ubuntu 18.04 has 5.4.0

The instructions provided below specify the steps to build Puppet 5.5.0 on Linux on IBM Z for the following distributions

  • RHEL (6.9, 7.3, 7.4)
  • SLES (11 SP4, 12 SP2, 12 SP3)
  • Ubuntu (16.04, 17.10, 18.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.

  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writeable directory anywhere you'd like to place it.

Step 1: Puppet Master Installation

1.1) Install following dependencies

  • RHEL (6.9, 7.3, 7.4)

    sudo yum install -y gcc-c++ readline-devel tar openssl unzip libyaml-devel PackageKit-cron openssl-devel make git wget sqlite-devel glibc-common hostname 
    
  • SLES (11 SP4, 12 SP2, 12 SP3)

    sudo zypper install -y gcc-c++ readline-devel tar openssl unzip libopenssl-devel make git wget sqlite-devel glibc-locale cron net-tools curl
    
    • Build Openssl 1.0.2k
      cd /<source_root>/
      wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2k.tar.gz
      tar zxf openssl-1.0.2k.tar.gz
      cd openssl-1.0.2k
      ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib shared zlib-dynamic
      make
      sudo make install
  • Ubuntu (16.04, 17.10)

    sudo apt-get update
    sudo apt-get install -y g++ libreadline6 libreadline6-dev tar openssl unzip libyaml-dev libssl-dev make git wget libsqlite3-dev libc6-dev cron locales ruby ruby-dev
    
  • Ubuntu (18.04)

    sudo apt-get update
    sudo apt-get install -y g++ libreadline7 libreadline-dev tar openssl unzip libyaml-dev libssl-dev make git wget libsqlite3-dev libc6-dev cron locales ruby ruby-dev
    

1.2) Download and install Ruby

  • RHEL (6.9, 7.3, 7.4)

    cd /<source_root>/
    wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.9.tar.gz
    tar -xvf ruby-2.2.9.tar.gz
    cd ruby-2.2.9
    ./configure && make && sudo make install
  • SLES (11 SP4, 12 SP2, 12 SP3)

    cd /<source_root>/
    wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.9.tar.gz
    tar -xvf ruby-2.2.9.tar.gz
    cd ruby-2.2.9
    ./configure LDFLAGS='-L/<source_root>/openssl-1.0.2k' --with-openssl-include=/<source_root>/openssl-1.0.2k/include --with-openssl-dir=/usr/
    make && sudo make install

1.3) Download cacert file (For SLES 11 SP4 only)

cd /<source_root>/
wget https://raw.githubusercontent.com/curl/curl/curl-7_53_0/lib/mk-ca-bundle.pl
perl mk-ca-bundle.pl -k
export SSL_CERT_FILE=/<src_root>/ca-bundle.crt

1.4) Install bundler

  • RHEL (6.9, 7.3, 7.4) and SLES (12 SP2, 12 SP3)

    cd /<source_root>/
    sudo /usr/local/bin/gem install bundler rake-compiler	
    
  • SLES 11 SP4

    cd /<source_root>/
    sudo -E /usr/local/bin/gem install bundler rake-compiler	
    
  • Ubuntu (16.04, 17.10, 18.04)

    cd /<source_root>/
    sudo /usr/bin/gem install bundler rake-compiler	
    

1.5) Install Puppet

  • RHEL (6.9, 7.3, 7.4) and SLES (12 SP2, 12 SP3)
    cd /<source_root>/
    sudo /usr/local/bin/gem install puppet -v 5.5.0
  • SLES 11 SP4
    cd /<source_root>/
    sudo -E /usr/local/bin/gem install puppet -v 5.5.0
  • Ubuntu (16.04, 17.10, 18.04)
    cd /<source_root>/
    sudo /usr/bin/gem install puppet -v 5.5.0

1.6) Locate the $confdir by command

Note: Please make sure the directory /usr/local/lib has sufficient read and execute permissions to run the above command. Incase it doesn't, run sudo chmod 755 /usr/local/lib to give the necessary permissions. Make sure that /usr/local/bin is available in PATH environment variable.

    confdir=`puppet master --configprint confdir`
    echo $confdir

The output gives the directory. If such directory does not exist, create one.

    mkdir -p $confdir

1.7) Create necessary directories and files in $confdir

    mkdir $confdir/modules
    mkdir $confdir/manifests
    cd $confdir
    touch puppet.conf
    wget https://raw.githubusercontent.com/puppetlabs/puppet/master/conf/auth.conf
    mkdir -p $confdir/opt/puppetlabs/puppet
    mkdir -p $confdir/var/log/puppetlabs

1.8) Create "puppet" user and group

    sudo useradd -d /home/puppet -m -s /bin/bash puppet
    sudo /usr/local/bin/puppet resource group puppet ensure=present

Note: Set a user specified password for puppet user .Running sudo passwd puppet will prompt for new password

1.9) Add the following parameters to $confdir/puppet.conf (assuming hostname of the master machine is master.myhost.com)

Note: Hostname can found by running the command hostname -f

    [main]
          logdir = $confdir/var/log/puppetlabs
          basemodulepath = $confdir/modules
          server = master.myhost.com
          user  = puppet
          group = puppet
          pluginsync = false
     [master]
          certname = master.myhost.com
          autosign = true

1.10) The Puppet master runs on TCP port 8140. This port needs to be open on your master firewall (and any intervening firewalls and network devices), and your agent must be able to route and connect to the master. To do this, you need to have an appropriate firewall rule on your master, such as the following rule for the Netfilter firewall

    sudo iptables -A INPUT -p tcp -m state --state NEW --dport 8140 -j ACCEPT 

Step2: Puppet Agent Installation

2.1) Install following dependencies

  • RHEL (6.9, 7.3, 7.4)

    sudo yum install -y gcc-c++ readline-devel tar openssl unzip libyaml-devel PackageKit-cron openssl-devel make git wget sqlite-devel glibc-common hostname 
    
  • SLES (11 SP4, 12 SP2, 12 SP3)

    sudo zypper install -y gcc-c++ readline-devel tar openssl unzip libopenssl-devel make git wget sqlite-devel glibc-locale cron net-tools curl
    
    • Build Openssl 1.0.2k
      cd /<source_root>/
      wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2k.tar.gz
      tar zxf openssl-1.0.2k.tar.gz
      cd openssl-1.0.2k
      ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib shared zlib-dynamic
      make
      sudo make install
  • Ubuntu (16.04, 17.10)

    sudo apt-get update
    sudo apt-get install -y g++ libreadline6 libreadline6-dev tar openssl unzip libyaml-dev libssl-dev make git wget libsqlite3-dev libc6-dev cron locales ruby ruby-dev
    
  • Ubuntu (18.04)

    sudo apt-get update
    sudo apt-get install -y g++ libreadline7 libreadline-dev tar openssl unzip libyaml-dev libssl-dev make git wget libsqlite3-dev libc6-dev cron locales ruby ruby-dev
    

2.2) Download and install Ruby

  • RHEL (6.9, 7.3, 7.4)

    cd /<source_root>/
    wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.9.tar.gz
    tar -xvf ruby-2.2.9.tar.gz
    cd ruby-2.2.9
    ./configure && make && sudo make install
  • SLES (11 SP4, 12 SP2, 12 SP3)

    cd /<source_root>/
    wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.9.tar.gz
    tar -xvf ruby-2.2.9.tar.gz
    cd ruby-2.2.2
    ./configure LDFLAGS='-L/<source_root>/openssl-1.0.2k' --with-openssl-include=/<source_root>/openssl-1.0.2k/include --with-openssl-dir=/usr/
    make && sudo make install

2.3) Download cacert file (For SLES 11 SP4 only)

cd /<source_root>/
wget https://raw.githubusercontent.com/curl/curl/curl-7_53_0/lib/mk-ca-bundle.pl
perl mk-ca-bundle.pl -k
export SSL_CERT_FILE=/<src_root>/ca-bundle.crt

2.4) Install bundler

  • RHEL (6.9, 7.3, 7.4) and SLES (12 SP2, 12 SP3)

    cd /<source_root>/
    sudo /usr/local/bin/gem install bundler rake-compiler	
    
  • SLES 11 SP4

    cd /<source_root>/
    sudo -E /usr/local/bin/gem install bundler rake-compiler	
    
  • Ubuntu (16.04, 17.10, 18.04)

    cd /<source_root>/
    sudo /usr/bin/gem install bundler rake-compiler	
    

2.5) Install Puppet

  • RHEL (6.9, 7.3, 7.4) and SLES (12 SP2, 12 SP3)
    cd /<source_root>/
    sudo /usr/local/bin/gem install puppet -v 5.5.0
  • SLES 11 SP4
    cd /<source_root>/
    sudo -E /usr/local/bin/gem install puppet -v 5.5.0
  • Ubuntu (16.04, 17.10, 18.04)
    cd /<source_root>/
    sudo /usr/bin/gem install puppet -v 5.5.0

2.6) Locate the $confdir by command

Note: Please make sure the directory /usr/local/lib has sufficent read and execute permissions to run the above command. Incase it doesn't, run sudo chmod 755 /usr/local/lib to give the necessary permissions. Make sure that /usr/local/bin is available in PATH environment variable.

    confdir=`puppet agent --configprint confdir`
    echo $confdir

The output gives the directory. If such directory does not exist, create one.

    mkdir -p $confdir

2.7) Create necessary directories and files in $confdir

    cd $confdir
    mkdir -p $confdir/opt/puppetlabs/puppet
    mkdir -p $confdir/var/log/puppetlabs
    touch puppet.conf

2.8) Add the following parameters to $confdir/puppet.conf (assuming hostname of the master machine is master.myhost.com and hostname of the agent machine is agent.myhost.com)

Note: Hostname can found by running the command hostname -f

    [main]
          logdir =  $confdir/var/log/puppetlabs
          basemodulepath = /etc/puppetlabs/puppet/modules
          server = master.myhost.com
          user  = puppet
          group = puppet
          pluginsync = false
     [agent]
          certname = agent.myhost.com
          report = true
          pluginsync = false

2.9) Add an entry in /etc/hosts file with ipaddress and hostname of master node

     sudo vi /etc/hosts
     <master ipaddress> <master hostname>

Step3: Connecting the Master and Agent for the first time

3.1) Run the master application on master machine (assuming with hostname master.myhost.com)

    puppet master --verbose --no-daemonize 

The --verbose option outputs verbose logging and the --no-daemonize option keeps the daemon in the foreground and redirects output to standard output. You can also add the --debug option to produce more verbose debug output from the daemon.

3.2) On the agent application (assuming the hostname of the agent is agent.myhost.com)

    puppet agent --test 

Note: The following errors might be seen after execution of the above step

Info: Retrieving pluginfacts
Error: /File[/opt/puppetlabs/puppet/cache/facts.d]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///pluginfacts
Info: Retrieving plugin
Error: /File[/opt/puppetlabs/puppet/cache/lib]: Could not evaluate: Could not retrieve information from environment production source(s) puppet://master.myhost.com/plugins

This is because you don't have any plugins to syn yet, and the pluginsyn property is set to be true by default. So solutions are:

1) Disable the setting in the agent's 'puppet.conf' file by setting  pluginsyn=false. Or 

2) Create at least one plugin ( By running puppet module install saz-sudo  on master)

Step4: Testing

For testing, run the tests from the source code on Master machine.

4.1) Switch user to puppet, clone Puppet git repository in /home/puppet and execute "bundle install" to install the required gems

    su puppet
    cd /home/puppet
    git clone git://github.com/puppetlabs/puppet
    cd puppet
    git checkout 5.5.0
    export SSL_CERT_FILE=/<src_root>/ca-bundle.crt        # (For SLES 11 SP4 only)
    bundle install --path .bundle/gems/

4.2) Running the test cases

Few testcases need to be executed as root user and others as puppet user.

4.2.1) Execute testcases as root user:

* Unit testcases, except ssl, face, indirector, network related testcases, should be executed as root user.
* The integration testcases for provider and type should be executed as root user.
* Note: Run the below commands as root user.You can switch to root user by running exit, if you are currently switched to puppet user.

  • Create a shell script
    For example,rootuser_tests.sh
	cd /home/puppet/puppet  
	touch rootuser_tests.sh  
	chmod +x rootuser_tests.sh  
  • Add the following content to the shell script
	#!/bin/bash
	set -e
		
	echo "Running Unit testcases as root user"
	declare -a unittests1
	unittests1=$(ls spec/unit|egrep -v "ssl|face|indirector|network")
	unittest_list1=($unittests1)
	for i in "${unittest_list1[@]}"
	do
	  bundle exec rspec "spec/unit/$i"
	done
		
	echo "Running Integration testcases as root user"
	declare -a integration1
	integration1=$(ls spec/integration|egrep "provider|type")
	integration_list1=($integration1)
	for j in "${integration_list1[@]}"
	do
	  bundle exec rspec --exclude-pattern ./spec/integration/provider/service/systemd_spec.rb "spec/integration/$j"
	done
  • Run the shell script

    • Ubuntu (16.04, 17.10, 18.04)
    locale-gen "en_US.UTF-8"
    export LC_ALL="en_US.UTF8"
    ./rootuser_tests.sh
    
    • RHEL (6.9, 7.3, 7.4) and SLES (11 SP4, 12 SP2, 12 SP3)
    export LC_ALL="en_US.UTF8"
    ./rootuser_tests.sh
    
4.2.2) Execute testcases as puppet user

* ssl, face, indirector, network related unit testcases should be executed as puppet user.
* The integration testcases except provider and type related testcases should be executed as puppet user.
* data_binding_spec.rb file is not executed as it does not involve any testcases to be invoked directly.

  • Create a shell script
    For example puppetuser_tests.sh
	cd /home/puppet/puppet
	touch puppetuser_tests.sh
	chmod +x puppetuser_tests.sh
  • Add the following content to the script
	#!/bin/bash
	set -e
		
	echo "Running Unit testcases as puppet user"
	declare -a unittests2
	unittests2=$(ls spec/unit|egrep "ssl|face|indirector|network")
	unittest_list2=($unittests2)
	for i in "${unittest_list2[@]}"
	do
		bundle exec rspec "spec/unit/$i"
	done
		
	echo "Running Integration testcases as puppet user"
	declare -a integration2
	integration2=$(ls spec/integration|egrep -v "data_binding_spec.rb|provider|type")
	integration_list2=($integration2)
	for j in "${integration_list2[@]}"
	do
	  bundle exec rspec "spec/integration/$j"
	done
  • Switch user to puppet
	su puppet
  • Run the shell script
	./puppetuser_tests.sh

Note: In case of below test case failure create a softlink as sudo ln -s /bin/touch /usr/bin/touch.

1) Puppet::Transaction when filtering with tags should propagate events correctly from a tagged container when running with tags
   Failure/Error: expect(Puppet::FileSystem.exist?(file1)).to be_truthy

     expected: truthy value
          got: false
   # ./spec/integration/transaction_spec.rb:371:in `block (3 levels) in <top (required)>'

Note: Following test failure is observed only on Ubuntu 18.04 and can be ignored:

Puppet::Type::File::ParameterSource#validate should strip trailing forward slashes
Failure/Error: expect(resource[:source]).to eq(%w{file:/foo/bar\\}) 

For more details refer: https://tickets.puppetlabs.com/browse/PUP-8708

References:

https://puppetlabs.com/

Clone this wiki locally