Handson1: Difference between revisions
From Gridkaschool
Jump to navigationJump to search
(132 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
== Hands-On == |
== Hands-On == |
||
=== Environment === |
=== Environment === |
||
# Login via ssh to the workgroup server |
# Login via ssh to the workgroup server gridkalogin01.desy.de with your assigned account |
||
# Check if you can login via ssh to |
# 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 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 |
||
=== Puppet first steps === |
|||
=== First steps === |
|||
# Use the puppet RAL to examine and configure the VM node [[handson11|solution]] |
# Use the puppet RAL to examine and configure the VM node [[handson11|solution]] |
||
## Show all managed resources |
## Show all managed resources |
||
Line 12: | Line 13: | ||
## Show resource of the created user |
## Show resource of the created user |
||
## Delete the testuser |
## Delete the testuser |
||
## HINT: |
## HINT: |
||
##* puppet resource --help |
##* puppet resource --help |
||
##* puppet describe |
##* puppet describe |
||
##* https://docs. |
##* https://docs.puppet.com/puppet/latest/reference/type.html#user |
||
# Write the first Manifest |
|||
=== Manifests === |
|||
## Create a puppet manifest which creates the testuser ''handson1create.pp'' wh |
|||
# Write the first Manifest [[Media:puppet_handson12.tar.gz|solution]] |
|||
## Create a puppet manifest which creates two testuser. Filename: ''handson1create.pp'' |
|||
## Create a puppet manifest which removes both testuser. Filename: ''handson1remove.pp'' |
|||
## Concatenate both puppet manifest. Filename: ''handson1combine.pp'' |
|||
## Apply the manifests to your node. |
|||
## Try to understand why the ''handson1combine.pp'' manifest fails? |
|||
## Hint: |
|||
##* https://docs.puppet.com/puppet/latest/reference/lang_resources.html#uniqueness |
|||
##* puppet apply --help |
|||
# 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'' |
|||
## Apply the manifest to your node |
|||
## Examine what happens if you re-apply the manifest. |
|||
## Add a line to the file ''/etc/motd'' and re-apply the manifest |
|||
## Hint: |
|||
##* https://docs.puppet.com/puppet/latest/reference/type.html#file |
|||
# Write the third Manifest [[Media:handson13.pp|solution]] |
|||
## 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 |
|||
## Hint: |
|||
##* https://docs.puppet.com/puppet/latest/reference/type.html#notify |
|||
##* https://docs.puppet.com/puppet/latest/reference/lang_relationships.html |
|||
##* 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]] |
|||
## Copy the file /etc/ssh/sshd_config in the folder ''/tmp'' |
|||
## Create a manifest which defines the following resources in the described order |
|||
### Install package sshd |
|||
### Copy the file from ''/tmp'' to ''/etc/ssh/sshd_config'' |
|||
### 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 without "--noop" parameter |
|||
# Improve the third manifest. [[Media:handson15.tar.gz|solution]] |
|||
## The text ''Hello World'' should be in a variable. |
|||
## 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. |
|||
## Hints: |
|||
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_variables.html |
|||
##* <source lang="text">man facter</source> |
|||
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_conditional.html |
|||
##* https://forge.puppetlabs.com/puppetlabs/stdlib#str2bool |
|||
=== Classes And Modules === |
|||
# Write your first class [[Media:Sshd_class.tar.gz|solution]] |
|||
## transform the the sshd example manifest to a class. |
|||
## Apply the manifest. And examine if the manifest is still working |
|||
## 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 |
|||
## Hints: |
|||
##* Classes are blocks of resources.They separate the definition and the declarations. |
|||
##* Syntax:<br />class my_class {<br />... puppet code ...<br />} |
|||
##* A class could be instantiated/declared with |
|||
##** ''include foo'' |
|||
##** ''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]] |
|||
## A module is a directory tree which stores all manifests, files, templates, tests which belong to one feature |
|||
## Create the following tree structure<br />sshd/<br />sshd/files<br />sshd/manifests<br /> |
|||
## 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 "include sshd"'' |
|||
## Copy the ''/etc/ssh/sshd_config'' file to sshd/files and edit the file resource (see hints) |
|||
## Hints: |
|||
##* https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html |
|||
##* https://docs.puppetlabs.com/references/latest/man/apply.html |
|||
##* https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html#files |
|||
# Write your first pretty module [[Media:Puppet_sshd2.tar.gz|solution]] |
|||
## 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 |
|||
## create for each subclass an seperate file under manifest |
|||
## 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. |
|||
## Move the ordering from the resources to the init class using ''chaining arrows'' |
|||
## Hints: |
|||
##* Subclasses are referenced with the double colon syntax. ''foo::bar'' |
|||
##* https://docs.puppetlabs.com/puppet/3.8/reference/modules_fundamentals.html |
|||
##* https://docs.puppetlabs.com/puppet/3.8/reference/lang_relationships.html#chaining-arrows |
|||
=== Templates === |
|||
# Write a manifest which utilize templates [[Media:template.tar.gz|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 |
|||
# 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 |
|||
#* http://blog.chriss-baumann.de/2009/02/03/ruby-string-to-integer |
|||
=== Node definitions === |
|||
# Write a node definition which includes the pretty ''sshd module'' [[Media:node.pp|solution]] |
|||
# Apply the node definition (don't forget the modulepath) |
|||
# Hints: |
|||
#* https://docs.puppetlabs.com/puppet/latest/reference/lang_node_definitions.html |
Latest revision as of 10:54, 9 August 2016
Hands-On
Environment
- Login via ssh to the workgroup server gridkalogin01.desy.de with your assigned account
- 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
First steps
- Use the puppet RAL to examine and configure the VM node solution
- Show all managed resources
- Show description of the resource service
- Show all configured services
- Create a testuser
- Show resource of the created user
- Delete the testuser
- HINT:
- puppet resource --help
- puppet describe
- https://docs.puppet.com/puppet/latest/reference/type.html#user
Manifests
- Write the first Manifest solution
- Create a puppet manifest which creates two testuser. Filename: handson1create.pp
- Create a puppet manifest which removes both testuser. Filename: handson1remove.pp
- Concatenate both puppet manifest. Filename: handson1combine.pp
- Apply the manifests to your node.
- Try to understand why the handson1combine.pp manifest fails?
- Hint:
- https://docs.puppet.com/puppet/latest/reference/lang_resources.html#uniqueness
- puppet apply --help
- Write the second Manifest solution
- Create a puppet manifest which creates the file /etc/motd with the content Hello World!. Filename: handson1motd.pp
- Apply the manifest to your node
- Examine what happens if you re-apply the manifest.
- Add a line to the file /etc/motd and re-apply the manifest
- Hint:
- Write the third Manifest solution
- 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
- Hello World 1
- Hint:
- https://docs.puppet.com/puppet/latest/reference/type.html#notify
- https://docs.puppet.com/puppet/latest/reference/lang_relationships.html
- Resources with lower case are instantiating, Resources with first letter upper case are reference
- 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
- Write the fourth manifest to configure the sshd daemon solution
- Copy the file /etc/ssh/sshd_config in the folder /tmp
- Create a manifest which defines the following resources in the described order
- Install package sshd
- Copy the file from /tmp to /etc/ssh/sshd_config
- 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
Notice: /Stage[main]/Main/File[foo]/content: current_value {md5}...., should be {md5}.... (noop)
- Apply the manifest without "--noop" parameter
- Improve the third manifest. solution
- The text Hello World should be in a variable.
- 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.
- Hints:
Classes And Modules
- Write your first class solution
- transform the the sshd example manifest to a class.
- Apply the manifest. And examine if the manifest is still working
- 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
- Hints:
- Classes are blocks of resources.They separate the definition and the declarations.
- Syntax:
class my_class {
... puppet code ...
} - A class could be instantiated/declared with
- include foo
- class{'foo':}
- Classes could be parameterized
class{'foo':
bar => 42,
}
- 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 solution
- A module is a directory tree which stores all manifests, files, templates, tests which belong to one feature
- Create the following tree structure
sshd/
sshd/files
sshd/manifests - 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 "include sshd"
- Copy the /etc/ssh/sshd_config file to sshd/files and edit the file resource (see hints)
- Hints:
- Write your first pretty module solution
- 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
- create for each subclass an seperate file under manifest
- 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.
- Move the ordering from the resources to the init class using chaining arrows
- Hints:
- Subclasses are referenced with the double colon syntax. foo::bar
- https://docs.puppetlabs.com/puppet/3.8/reference/modules_fundamentals.html
- https://docs.puppetlabs.com/puppet/3.8/reference/lang_relationships.html#chaining-arrows
- It is best practice to divide a feature in subclasses.
Templates
- 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
- 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
- http://blog.chriss-baumann.de/2009/02/03/ruby-string-to-integer
Node definitions
- Write a node definition which includes the pretty sshd module solution
- Apply the node definition (don't forget the modulepath)
- Hints: