H5GBo

                    "It's hard to make satire over satire"

                    "Andy" aka Andrus Valvur
                    ETV 201705151830 AK 20:40

Intro to Puppetlabs Puppet on Ubuntu LTS (16.04)
================================================

1. "Zesty" is not in repo yet.

2. Scripting is easier with some OOP/programming background.

3. Entered depersonalization phase (less fun):

    + Switched from Ruby to Java.
    + "master" is called "server" now
    + "puppet" is called "agent" now

4. There is "Apache/Passenger Puppet" fork which is not puppetlabs
   (still Ruby and Luke Kanies (creator) terminology).

Prolog
------

Ubuntu Gnome 16.04.2

0. Install virtualbox guest additions

1. apt-get autoremove --purge libreoffice* openoffice* rhythmbox totem

2. apt-get update
   apt-get upgrade
   apt-get install vim plank

3. Autostart plank, remove update-notifier from autostart (Startup Applications). Automatically check for updates -> Never (Software & Update)

  sed -i 's/NoDisplay=true/NoDisplay=false/g' /etc/xdg/autostart/*.desktop

4. grub:

  # cat /etc/defaul/grub | tail -n 2
  GRUB_CMDLINE_LINUX_DEFAULT="" # "splash quiet" # <<<
  GRUB_TERMINAL=console                          # <<<
  # update-grub

5. sudo:

  # cat /etc/sudoers | grep ^%
  %admin ALL=(ALL) NOPASSWD:ALL
  %sudo  ALL=(ALL) NOPASSWD:ALL

6. apt-get install putty

7. Change host name for your Puppet server:

  # cat /etc/hostname
  puppet

  # cat /etc/hosts
  10.0.2.100      puppet
  127.0.0.1       localhost
  127.0.1.1       puppet

8. # mkdir puppet
   # cd puppet/
   # wget -c https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
   # dpkg -i puppetlabs-release-pc1-xenial.deb
   # sudo apt-get update

9. Shutdown. Clone machine as "UGnome Clone"
   [v] Reinitialize MAC addresses of all network cards

Install Puppet
--------------

Two hosts: puppet and clone

1.1. Put UGnome into NAT network (virtual box):

  DNS:  x.x.x.x
  DHCP: 10.0.2.4
  GATEWAY: 10.0.2.2
  NETWORK: 10.0.2.0/24

1.3. Give it a static IP 10.0.2.100

  # service
  # systemctl disable NetworkManager.service
  # cat /etc/network/interfaces
  auto lo enp0s3
  iface lo inet loopback

  iface enp0s3 inet static
  address 10.0.2.100
  netmask 255.255.255.0
  gateway 10.0.2.2
  dns-nameservers x.x.x.x

  # systemctl restart networking

1.4. Change host name for your Puppet server:

  # cat /etc/hostname
  puppet

  # cat /etc/hosts
  10.0.2.100      puppet
  127.0.0.1       localhost
  127.0.1.1       puppet

1.5. Puppet server:

  # sudo apt-get install puppetserver
  # systemctl start puppetserver (1-2 min)
  # systemctl status puppetserver
  .. active (running)
  # systemctl enable puppetserver

2.1. UGnome Clone: Give it a dynamic IP
---------------------------------------

  # systemctl status NetworkManager.service
  # systemctl start NetworkManager.service
  # cat /etc/network/interfaces
  auto lo enp0s3
  iface lo inet loopback

  # systemctl restart networking
  # dhclient enp0s3   <-- if switching from static to dynamic

2.2. UGnome Clone: Change Desktop Wallpaper (Background)

2.3. UGnome Clone: Change host name for your Puppet agent:

  # cat /etc/hostname
  clone

  # cat /etc/hosts
  10.0.2.100      puppet     # It's master here
  127.0.0.1       localhost
  127.0.1.1       clone

2.4. Puppet agent

  # apt-get install puppet-agent  <= PUPPET-AGENT!
  # systemctl start puppet
  # systemctl enable puppet

Signing certificates and testing
--------------------------------

Sometimes resigning is needed..

  $ sudo /opt/puppetlabs/bin/puppet cert list
  "puppet.lan" (SHA256) FA:93:1E:20:C6:72:E1:42:EC:80:60:01:60:89:A6:A9:F2:0D:48:31:AD:FA:55:B5:FB:0E:E0:7F:AC:8F:19:44
  $ sudo /opt/puppetlabs/bin/puppet cert sign --all
  $ cat /etc/puppetlabs/code/environments/production/manifests/site.pp
  file {'/tmp/it_works.txt':
    ensure  => present,
    mode    => '0644',
    content => "It works on ${ipaddress_enp0s3}!\n",
  }

On clone (agent): immediate test

  clone:~$ sudo /opt/puppetlabs/bin/puppet agent --test

FAQ
---

1. How to change the polling interval of the Puppet server? [3]

  clone:~$ cat /etc/puppetlabs/puppet/puppet.conf | grep ^[^#]
  runinterval=60
  clone:~$ sudo systemctl restart puppet
  clone:~$ cat /tmp/it_works.txt
  R: It works on 10.0.2.18!

2. Why my "master" host name is "puppet"?

  This is default name, can be changed in puppet.conf

    server=boss.com

3. Where is my puppet.conf?

  $ dpkg -L puppet-agent | grep puppet.conf$
  /etc/puppetlabs/puppet/puppet.conf

4. Installing apache via puppet

  # /opt/puppetlabs/bin/puppet module install puppetlabs-apache
  Notice: Preparing to install into
    /etc/puppetlabs/code/environments/production/modules ...
  Notice: Downloading from https://forgeapi.puppet.com ...
  Notice: Installing -- do not interrupt ...
  /etc/puppetlabs/code/environments/production/modules
  └─┬ puppetlabs-apache (v1.11.0)
    ├── puppetlabs-concat (v2.2.1)
    └── puppetlabs-stdlib (v4.17.0)

  # vi /etc/puppetlabs/code/environments/production/manifests/site.pp

  node 'clone' {
    class { 'apache': }       # use apache module
    apache::vhost { 'clone':  # define vhost resource
      port    => '80',
      docroot => '/var/www/html'
    }
  }

  clone:~$ sudo /opt/puppetlabs/bin/puppet agent --test
  clone:~$ firefox localhost &

5. I need more tips on [4]..

  $ echo '''
  > ^C
  $ echo \'\'\'
  '''
  $ echo \'\'\' | sed 's/'\''/q/g'
  qqq
  $ echo \'\'\' > qqq
  $ sed -e 's/'\''/q/g' qqq
  qqq
  $ sed -ie 's/'\''/q/g' qqq
  $ cat qqq
  qqq
  $ ls qqq*
  qqq  qqqe
  $ cat qqqe
  '''

6. Plank and puppet

  $ cat ~/.config/plank/dock1/launchers/nautilus.dockitem
  [PlankDockItemPreferences]
  Launcher=file:///usr/share/applications/nautilus.desktop
  $ cat ~/.config/plank/dock1/launchers/nautilus.dockitem
  [PlankDockItemPreferences]
  Launcher=file:///usr/share/applications/plank.desktop

You need to restart plank to apply this changes

  $ killall plank
  $ plank &

Links:
------

1. https://www.digitalocean.com/community/tutorials
        /how-to-install-puppet-4-on-ubuntu-16-04

2. https://www.digitalocean.com/community/tutorials
        /getting-started-with-puppet-code-manifests-and-modules

   2a. https://www.digitalocean.com/community/tutorials
            /how-to-install-puppet-to-manage-your-server-infrastructure

3. https://serverfault.com/questions/218912
        /how-to-change-the-polling-interval-of-the-puppet-master

4. https://www.puppetcookbook.com

