Playing with Puppet part 1

The relevant files can be found here: https://github.com/Spodah/puppet-practices
I began the exercise at 2017-4-3 22:45 local time. The exercise was done HP pavillion p6-2020sc using Kubuntu 16.04.2 from live-USB

First, installing Puppet: sudo apt-get update, sudo apt-get install puppet

Then, checking that the environment is sane and the installation works: kubuntu@kubuntu:~$ sudo puppet apply -e ‘file { “/tmp/hellopuppet”: content => “Hello World\n” }’
Notice: Compiled catalog for kubuntu.elisa in environment production in 0.16 seconds
Notice: /Stage[main]/Main/File[/tmp/hellopuppet]/ensure: defined content as ‘{md5}e59ff97941044f85df5297e1c302d260’
Notice: Finished catalog run in 0.02 seconds
Testing that puppet did what it said it did:
kubuntu@kubuntu:~$ cat /tmp/hellopuppet
Hello World

The environment appears to be working as it should be. By now it was 22:57. In the next part, I attempted to create a puppet module that creates a text file and installs the latest version of IPython 3.
kubuntu@kubuntu:~$ cd /etc/puppet/
kubuntu@kubuntu:/etc/puppet$ ls
etckeeper-commit-post etckeeper-commit-pre manifests modules puppet.conf
kubuntu@kubuntu:/etc/puppet$ cd modules
kubuntu@kubuntu:/etc/puppet/modules$ ls
kubuntu@kubuntu:/etc/puppet/modules$ mkdir ipython
mkdir: cannot create directory ‘ipython’: Permission denied
kubuntu@kubuntu:/etc/puppet/modules$ sudo mkdir ipython
kubuntu@kubuntu:/etc/puppet/modules$ cd ipython
kubuntu@kubuntu:/etc/puppet/modules/ipython$ sudo mkdir modules
kubuntu@kubuntu:/etc/puppet/modules/ipython$ cd modules
After this, I created file init.pp. The initial version only creates a file in /tmp/(see github) and adds text to it, just like the hello world script above.
Next, testing the file:
kubuntu@kubuntu:/etc/puppet/modules/ipython/modules$ sudo puppet ipython
Error: Unknown Puppet subcommand ‘ipython’
See ‘puppet help’ for help on available puppet subcommands
kubuntu@kubuntu:/etc/puppet/modules/ipython/modules$ sudo puppet -e ipython
Error: Could not parse application options: invalid option: -e
kubuntu@kubuntu:/etc/puppet/modules/ipython/modules$ sudo puppet apply -e ipython
Error: Could not parse for environment production: Syntax error at end of file at line 1 on node kubuntu.elisa
Error: Could not parse for environment production: Syntax error at end of file at line 1 on node kubuntu.elisa
kubuntu@kubuntu:/etc/puppet/modules/ipython/modules$ sudo nano init.pp
kubuntu@kubuntu:/etc/puppet/modules/ipython/modules$ sudo puppet apply -e ‘class{“ipython”:}’
Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class ipython at line 1 on node kubuntu.elisa
Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Could not find declared class ipython at line 1 on node kubuntu.elisa
kubuntu@kubuntu:/etc/puppet/modules/ipython/modules$ cd ..
kubuntu@kubuntu:/etc/puppet/modules/ipython$ ls
modules
kubuntu@kubuntu:/etc/puppet/modules/ipython$ cd ..
kubuntu@kubuntu:/etc/puppet/modules$ ls
ipython
kubuntu@kubuntu:/etc/puppet/modules$ cd ipython
kubuntu@kubuntu:/etc/puppet/modules/ipython$ sudo mkdir manifests
kubuntu@kubuntu:/etc/puppet/modules/ipython$ sudo mv ./modules/init.pp ./manifests/init.pp
kubuntu@kubuntu:/etc/puppet/modules/ipython$ sudo del modules
sudo: del: command not found
kubuntu@kubuntu:/etc/puppet/modules/ipython$ cat manifests/init.pp
class ipython {
file { ‘/tmp/ipython’:
content => “Playing with puppets\n”
}
}
kubuntu@kubuntu:/etc/puppet/modules/ipython$ sudo rmdir modules
kubuntu@kubuntu:/etc/puppet/modules/ipython$ sudo puppet apply -e ‘class{“ipython”:}’
Notice: Compiled catalog for kubuntu.elisa in environment production in 0.16 seconds
Notice: /Stage[main]/Ipython/File[/tmp/ipython]/ensure: defined content as ‘{md5}38028b51833135efa362820b0daa7f8e’
Notice: Finished catalog run in 0.03 seconds
kubuntu@kubuntu:/etc/puppet/modules/ipython$ cat /tmp/ipython
Playing with puppets

After a few mistakes, the module was finally working. Next, making it install ipython3 as well. Again, the modified files are in github.
kubuntu@kubuntu:/etc/puppet/modules/ipython/manifests$ sudo puppet apply -e ‘class{“ipython”:}’
Notice: Compiled catalog for kubuntu.elisa in environment production in 0.67 seconds
Notice: /Stage[main]/Ipython/Package[ipython3]/ensure: ensure changed ‘purged’ to ‘latest’
Notice: Finished catalog run in 5.89 seconds
kubuntu@kubuntu:/etc/puppet/modules/ipython/manifests$ ipython3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
Type “copyright”, “credits” or “license” for more information.

IPython 2.4.1 — An enhanced Interactive Python.
? -> Introduction and overview of IPython’s features.
%quickref -> Quick reference.
help -> Python’s own help system.
object? -> Details about ‘object’, use ‘object??’ for extra details.

In [1]:
Here we can see that IPython3 was working as well. Now the time was 23:46.

Sources: http://terokarvinen.com/2017/aikataulu-%e2%80%93-palvelinten-hallinta-ict4tn022-2-%e2%80%93-5-op-uusi-ops-loppukevat-2017-p2
http://terokarvinen.com/2013/hello-puppet-revisited-%E2%80%93-on-ubuntu-12-04-lts
https://docs.puppet.com/puppet/latest/types/package.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s