Difference between revisions of "Handson1"

From Gridkaschool
(Manifests)
(Templates)
 
(30 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
=== Environment ===
 
=== Environment ===
 
# Login via ssh to the workgroup server gridkalogin01.desy.de with your assigned account
 
# Login via ssh to the workgroup server gridkalogin01.desy.de with your assigned account
# Check if you can login via ssh to you assigned VM as '''root''' - hint: An ssh key-pair was generated and put into your home directory on gridkalogin01. The public key was put in the root account of your VM
+
# Check if you can login via ssh to your assigned VM as '''root''' - hint: An ssh key-pair was generated and put into your home directory on gridkalogin01. The public key is copied to the root account of your VM
 
# Check if you can edit a text file on the wgs and the VM node. We provide vim, emacs, nano
 
# Check if you can edit a text file on the wgs and the VM node. We provide vim, emacs, nano
   
Line 28: Line 28:
 
##* https://docs.puppet.com/puppet/latest/reference/lang_resources.html#uniqueness
 
##* https://docs.puppet.com/puppet/latest/reference/lang_resources.html#uniqueness
 
##* puppet apply --help
 
##* puppet apply --help
# Write the second Manifest
+
# Write the second Manifest [[Media:Handson1motd.pp|solution]]
 
## Create a puppet manifest which creates the file ''/etc/motd'' with the content ''Hello World!''. Filename: ''handson1motd.pp''
 
## Create a puppet manifest which creates the file ''/etc/motd'' with the content ''Hello World!''. Filename: ''handson1motd.pp''
 
## Apply the manifest to your node
 
## Apply the manifest to your node
Line 34: Line 34:
 
## Add a line to the file ''/etc/motd'' and re-apply the manifest
 
## Add a line to the file ''/etc/motd'' and re-apply the manifest
 
## Hint:
 
## Hint:
##* https://docs.puppetlabs.com/references/3.stable/type.html#file
+
##* https://docs.puppet.com/puppet/latest/reference/type.html#file
 
# Write the third Manifest [[Media:handson13.pp|solution]]
 
# Write the third Manifest [[Media:handson13.pp|solution]]
## Write a manifest which writes 10 debug messages in the following '''order'''
+
## Write a manifest which writes 10 time ''Hello World'' followed by a number from 1 to 10. The messages should appear in the following '''order'''
 
##* Hello World 1<br />Hello World 2<br />Hello World 3<br />...<br />Hello World 10
 
##* Hello World 1<br />Hello World 2<br />Hello World 3<br />...<br />Hello World 10
 
## Hint:
 
## Hint:
##* https://docs.puppetlabs.com/references/3.stable/type.html#notify
+
##* https://docs.puppet.com/puppet/latest/reference/type.html#notify
##* https://docs.puppetlabs.com/puppet/3.8/reference/lang_relationships.html
+
##* https://docs.puppet.com/puppet/latest/reference/lang_relationships.html
 
##* Resources with lower case are instantiating, Resources with first letter upper case are reference
 
##* Resources with lower case are instantiating, Resources with first letter upper case are reference
 
# Write the fourth manifest to configure the sshd daemon [[Media:handson14.pp|solution]]
 
# Write the fourth manifest to configure the sshd daemon [[Media:handson14.pp|solution]]
Line 47: Line 47:
 
### Install package sshd
 
### Install package sshd
 
### Copy the file from ''/tmp'' to ''/etc/ssh/sshd_config''
 
### Copy the file from ''/tmp'' to ''/etc/ssh/sshd_config''
### Start the sshd daemon
+
### Ensure that the daemon is running and restart the sshd daemon when the config has changed
 
## Apply the manifest with "--noop" parameter the /etc/ssh/sshd_config file shouldn't be changed. No line like <source lang="text">Notice: /Stage[main]/Main/File[foo]/content: current_value {md5}...., should be {md5}.... (noop)</source>
 
## Apply the manifest with "--noop" parameter the /etc/ssh/sshd_config file shouldn't be changed. No line like <source lang="text">Notice: /Stage[main]/Main/File[foo]/content: current_value {md5}...., should be {md5}.... (noop)</source>
 
## Apply the manifest without "--noop" parameter
 
## Apply the manifest without "--noop" parameter
# Write the fifth manifest [[Media:handson15.tar.gz|solution]]
+
# Improve the third manifest. [[Media:handson15.tar.gz|solution]]
## Improve the third manifest. The text ''Hello World'' should be in a variable.
+
## The text ''Hello World'' should be in a variable.
## Examine the facts of the VM locally with ''facter''
+
## Examine the facts of the VM locally with ''facter'' and write a manifest which gives a debug message with the uptime and if the machine is virtualized.
## Write a manifest which gives a debug message if the machine is virtual machine and the uptime
 
## Run the manifest on your VM and on naf-school03
 
 
## Hints:
 
## Hints:
##* https://docs.puppetlabs.com/puppet/3.8/reference/lang_variables.html
+
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_variables.html
 
##* <source lang="text">man facter</source>
 
##* <source lang="text">man facter</source>
##* https://docs.puppetlabs.com/puppet/3.8/reference/lang_conditional.html
+
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_conditional.html
 
##* https://forge.puppetlabs.com/puppetlabs/stdlib#str2bool
 
##* https://forge.puppetlabs.com/puppetlabs/stdlib#str2bool
   
=== Classes ===
+
=== Classes And Modules ===
# Write your first class
+
# Write your first class [[Media:Sshd_class.tar.gz|solution]]
  +
## transform the the sshd example manifest to a class.
## Classes are blocks of resources
 
## They divide the definition and the declarations
 
## Classes could be parameterized
 
## Syntax:<br />class my_class {<br />... puppet code ...<br />}
 
## transform the fourth manifest (the sshd example) to a class.
 
 
## Apply the manifest. And examine if the manifest is still working
 
## Apply the manifest. And examine if the manifest is still working
## A class could be instantiated/declared with
 
##* ''include foo'' Statement
 
##* Resource like ''class{'foo':}''
 
##* Resource like with parameter<br />''class{'foo':<br />bar => 42,<br />}''
 
 
## Add the declaration to the end of the manifest. And re-apply the manifest
 
## Add the declaration to the end of the manifest. And re-apply the manifest
 
## Add a string as parameter to the class and print this string as debug message
 
## Add a string as parameter to the class and print this string as debug message
 
## Hints:
 
## Hints:
  +
##* Classes are blocks of resources.They separate the definition and the declarations.
##* https://docs.puppetlabs.com/puppet/3.8/reference/lang_classes.html
 
  +
##* Syntax:<br />class my_class {<br />... puppet code ...<br />}
##* https://docs.puppetlabs.com/puppet/3.8/reference/lang_classes.html#declaring-classes
 
  +
##* A class could be instantiated/declared with
 
  +
##** ''include foo''
=== Modules ===
 
  +
##** ''class{'foo':}''
  +
##** Classes could be parameterized<br />''class{'foo':<br />bar => 42,<br />}''
  +
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html
  +
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html#declaring-classes
 
# Write your first module [[Media:Puppet_sshd.tar.gz|solution]]
 
# Write your first module [[Media:Puppet_sshd.tar.gz|solution]]
 
## A module is a directory tree which stores all manifests, files, templates, tests which belong to one feature
 
## A module is a directory tree which stores all manifests, files, templates, tests which belong to one feature
Line 85: Line 79:
 
## Copy the sshd class manifest as sshd/manifests/init.pp
 
## Copy the sshd class manifest as sshd/manifests/init.pp
 
## Apply the module. Set the parameter ''--modulepath'' to the directory where sshd directory was created, and add ''-e &quot;include sshd&quot;''
 
## Apply the module. Set the parameter ''--modulepath'' to the directory where sshd directory was created, and add ''-e &quot;include sshd&quot;''
## Copy the config file from /tmp/examples to sshd/files and edit the file resource (see hints)
+
## Copy the ''/etc/ssh/sshd_config'' file to sshd/files and edit the file resource (see hints)
 
## Hints:
 
## Hints:
##* https://docs.puppetlabs.com/puppet/3.8/reference/modules_fundamentals.html
+
##* https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html
##* https://docs.puppetlabs.com/references/3.stable/man/apply.html
+
##* https://docs.puppetlabs.com/references/latest/man/apply.html
##* https://docs.puppetlabs.com/puppet/3.8/reference/modules_fundamentals.html#files
+
##* https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html#files
 
# Write your first pretty module [[Media:Puppet_sshd2.tar.gz|solution]]
 
# Write your first pretty module [[Media:Puppet_sshd2.tar.gz|solution]]
 
## It is best practice to divide a feature in subclasses.
 
## It is best practice to divide a feature in subclasses.
Line 108: Line 102:
   
 
=== Templates ===
 
=== Templates ===
  +
# Write a manifest which utilize templates [[Media:template.tar.gz|solution]]
# Templates could be used like static files
 
  +
#* Initialize a variable ''$myVar'' with a string.
# The difference is that the template will be evaluated before it is written
 
  +
#* write a file ''/tmp/testfile'' with the content of ''$myVar'' and the ''uptime'' fact
# Templates could use
 
#* Variables
 
#* Facts
 
#* Ruby Code (in fact they are standard ruby templates)
 
# Write a class which [[Media:template.tar.gz|solution]]
 
#* write a file ''/tmp/testfile''
 
#* In the class define a variable ''$myVar''
 
#* In the file write the content of ''$myVar'' and the ''uptime'' fact
 
 
#* Alter the output depending on the uptime hours. less then 24 hours write the uptime_hours otherwise the uptime_days
 
#* Alter the output depending on the uptime hours. less then 24 hours write the uptime_hours otherwise the uptime_days
 
# Hints:
 
# Hints:
  +
#* Templates will be evaluated before they are written to disk
  +
#* Templates could use
  +
#** Variables
  +
#** Facts
  +
#** Ruby Code (in fact they are standard ruby templates)
 
#* https://docs.puppetlabs.com/guides/templating.html
 
#* https://docs.puppetlabs.com/guides/templating.html
 
#* http://blog.chriss-baumann.de/2009/02/03/ruby-string-to-integer
 
#* http://blog.chriss-baumann.de/2009/02/03/ruby-string-to-integer

Latest revision as of 10:54, 9 August 2016

Hands-On

Environment

  1. Login via ssh to the workgroup server gridkalogin01.desy.de with your assigned account
  2. Check if you can login via ssh to your assigned VM as root - hint: An ssh key-pair was generated and put into your home directory on gridkalogin01. The public key is copied to the root account of your VM
  3. Check if you can edit a text file on the wgs and the VM node. We provide vim, emacs, nano

First steps

  1. Use the puppet RAL to examine and configure the VM node solution
    1. Show all managed resources
    2. Show description of the resource service
    3. Show all configured services
    4. Create a testuser
    5. Show resource of the created user
    6. Delete the testuser
    7. HINT:

Manifests

  1. Write the first Manifest solution
    1. Create a puppet manifest which creates two testuser. Filename: handson1create.pp
    2. Create a puppet manifest which removes both testuser. Filename: handson1remove.pp
    3. Concatenate both puppet manifest. Filename: handson1combine.pp
    4. Apply the manifests to your node.
    5. Try to understand why the handson1combine.pp manifest fails?
    6. Hint:
  2. Write the second Manifest solution
    1. Create a puppet manifest which creates the file /etc/motd with the content Hello World!. Filename: handson1motd.pp
    2. Apply the manifest to your node
    3. Examine what happens if you re-apply the manifest.
    4. Add a line to the file /etc/motd and re-apply the manifest
    5. Hint:
  3. Write the third Manifest solution
    1. Write a manifest which writes 10 time Hello World followed by a number from 1 to 10. The messages should appear in the following order
      • Hello World 1
        Hello World 2
        Hello World 3
        ...
        Hello World 10
    2. Hint:
  4. Write the fourth manifest to configure the sshd daemon solution
    1. Copy the file /etc/ssh/sshd_config in the folder /tmp
    2. Create a manifest which defines the following resources in the described order
      1. Install package sshd
      2. Copy the file from /tmp to /etc/ssh/sshd_config
      3. Ensure that the daemon is running and restart the sshd daemon when the config has changed
    3. Apply the manifest with "--noop" parameter the /etc/ssh/sshd_config file shouldn't be changed. No line like
      Notice: /Stage[main]/Main/File[foo]/content: current_value {md5}...., should be {md5}.... (noop)
      
    4. Apply the manifest without "--noop" parameter
  5. Improve the third manifest. solution
    1. The text Hello World should be in a variable.
    2. Examine the facts of the VM locally with facter and write a manifest which gives a debug message with the uptime and if the machine is virtualized.
    3. Hints:

Classes And Modules

  1. Write your first class solution
    1. transform the the sshd example manifest to a class.
    2. Apply the manifest. And examine if the manifest is still working
    3. Add the declaration to the end of the manifest. And re-apply the manifest
    4. Add a string as parameter to the class and print this string as debug message
    5. Hints:
  2. Write your first module solution
    1. A module is a directory tree which stores all manifests, files, templates, tests which belong to one feature
    2. Create the following tree structure
      sshd/
      sshd/files
      sshd/manifests
    3. Copy the sshd class manifest as sshd/manifests/init.pp
    4. Apply the module. Set the parameter --modulepath to the directory where sshd directory was created, and add -e "include sshd"
    5. Copy the /etc/ssh/sshd_config file to sshd/files and edit the file resource (see hints)
    6. Hints:
  3. Write your first pretty module solution
    1. It is best practice to divide a feature in subclasses.
      • install - Install the packages
      • config - Configure the feature
      • service - start the service
      • params - define the parameter of the feature
    2. create for each subclass an seperate file under manifest
    3. create the file init.pp
      • will be autoloaded if you declare the module
      • defines a class with the same name like the module
      • declare all subclasses.
    4. Move the ordering from the resources to the init class using chaining arrows
    5. Hints:

Templates

  1. Write a manifest which utilize templates solution
    • Initialize a variable $myVar with a string.
    • write a file /tmp/testfile with the content of $myVar and the uptime fact
    • Alter the output depending on the uptime hours. less then 24 hours write the uptime_hours otherwise the uptime_days
  2. Hints:

Node definitions

  1. Write a node definition which includes the pretty sshd module solution
  2. Apply the node definition (don't forget the modulepath)
  3. Hints: