Difference between revisions of "Handson1"

From Gridkaschool
(Puppet classes and modules)
(Puppet classes and modules)
Line 63: Line 63:
 
## Classes are blocks of resources
 
## Classes are blocks of resources
 
## They divide the definition and the declarations
 
## They divide the definition and the declarations
## Classes could could parameterized
+
## Classes could be parameterized
 
## Syntax:<br />class my_class {<br />... puppet code ...<br />}
 
## Syntax:<br />class my_class {<br />... puppet code ...<br />}
 
## transform the fourth manifest (the sshd example) to a class.
 
## transform the fourth manifest (the sshd example) to a class.

Revision as of 17:10, 27 August 2014

Hands-On

Environment

  1. Login via ssh to the workgroup server naf-school01.desy.de with your assigned account
  2. Check if you can login via ssh to you assigned VM as root
  3. Check if you can edit a text file on the wgs and the node. We provide vim, emacs, nano

Puppet 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:

Puppet Manifests

  1. Write the first Manifest
    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 debug messages 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. Create the folder /root/example
    2. Copy the file /etc/ssh/sshd_config in the folder /root/example
    3. Create a manifest which defines the following resources in the described order
      1. Install package sshd
      2. Copy the file from /root/example to /etc/ssh/sshd_config
      3. Start the sshd daemon
    4. 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)
      
    5. Apply the manifest without "--noop" parameter
  5. Write the fifth manifest solution
    1. Improve the third manifest. The text Hello World should be in a variable.
    2. Examine the facts of the VM locally with facter
    3. Write a manifest which gives a debug message if the machine is virtual machine and the uptime
    4. Run the manifest on your VM and on naf-school01
    5. Hints:

Puppet classes and modules

  1. Write your first class
    1. Classes are blocks of resources
    2. They divide the definition and the declarations
    3. Classes could be parameterized
    4. Syntax:
      class my_class {
      ... puppet code ...
      }
    5. transform the fourth manifest (the sshd example) to a class.
    6. Apply the manifest. And examine if the manifest is still working
    7. Add the declaration to the end of the manifest. And re-apply the manifest
    8. Add a string as parameter to the class and print this string as debug message
    9. 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 config file from /root/examples to sshd/files and edit the file resource (see hints)
    6. Hints:
  3. Write your first pretty module
    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