Handson1: Difference between revisions
From Gridkaschool
Jump to navigationJump to search
(63 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 |
||
=== |
=== 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 15: | Line 16: | ||
##* puppet resource --help |
##* puppet resource --help |
||
##* puppet describe |
##* puppet describe |
||
##* https://docs. |
##* https://docs.puppet.com/puppet/latest/reference/type.html#user |
||
=== |
=== Manifests === |
||
# Write the first Manifest |
|||
⚫ | |||
## Create a puppet manifest which creates two testuser. Filename: ''handson1create.pp'' |
## Create a puppet manifest which creates two testuser. Filename: ''handson1create.pp'' |
||
## Create a puppet manifest which removes both testuser. Filename: ''handson1remove.pp'' |
## Create a puppet manifest which removes both testuser. Filename: ''handson1remove.pp'' |
||
Line 24: | Line 26: | ||
## Try to understand why the ''handson1combine.pp'' manifest fails? |
## Try to understand why the ''handson1combine.pp'' manifest fails? |
||
## Hint: |
## Hint: |
||
##* https://docs. |
##* https://docs.puppet.com/puppet/latest/reference/lang_resources.html#uniqueness |
||
##* puppet apply --help |
##* puppet apply --help |
||
# Write the second Manifest [[Media: |
# 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 32: | 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. |
##* 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 |
## 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. |
##* https://docs.puppet.com/puppet/latest/reference/type.html#notify |
||
##* https://docs. |
##* 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]] |
||
## |
## Copy the file /etc/ssh/sshd_config in the folder ''/tmp'' |
||
## Copy the file /etc/ssh/sshd_config in the folder ''/root/example'' |
|||
## Create a manifest which defines the following resources in the described order |
## Create a manifest which defines the following resources in the described order |
||
### Install package sshd |
### Install package sshd |
||
### Copy the file from ''/ |
### 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 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 |
||
# |
# 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'' |
## 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-school01 |
|||
## Hints: |
## Hints: |
||
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_variables.html |
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_variables.html |
||
Line 59: | Line 58: | ||
##* https://docs.puppetlabs.com/puppet/latest/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 |
||
=== Puppet classes === |
|||
=== Classes And Modules === |
|||
# Write your first class |
|||
# Write your first class [[Media:Sshd_class.tar.gz|solution]] |
|||
## Classes are blocks of resources |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
## Apply the manifest. And examine if the manifest is still working |
## Apply the manifest. And examine if the manifest is still working |
||
⚫ | |||
⚫ | |||
⚫ | |||
##* 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: |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html |
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html |
||
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html#declaring-classes |
##* https://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html#declaring-classes |
||
=== Puppet modules === |
|||
# 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 |
||
## Create the following tree structure<br />sshd/<br />sshd/files<br />sshd/manifests<br /> |
## Create the following tree structure<br />sshd/<br />sshd/files<br />sshd/manifests<br /> |
||
## 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 include sshd'' |
## Apply the module. Set the parameter ''--modulepath'' to the directory where sshd directory was created, and add ''-e "include sshd"'' |
||
## Copy the |
## Copy the ''/etc/ssh/sshd_config'' file to sshd/files and edit the file resource (see hints) |
||
## Hints: |
## Hints: |
||
##* https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html |
##* https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html |
||
##* https://docs.puppetlabs.com/references/ |
##* https://docs.puppetlabs.com/references/latest/man/apply.html |
||
##* https://docs.puppetlabs.com/puppet/latest/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]] |
||
Line 101: | Line 98: | ||
## Hints: |
## Hints: |
||
##* Subclasses are referenced with the double colon syntax. ''foo::bar'' |
##* Subclasses are referenced with the double colon syntax. ''foo::bar'' |
||
##* https://docs.puppetlabs.com/puppet/ |
##* https://docs.puppetlabs.com/puppet/3.8/reference/modules_fundamentals.html |
||
##* https://docs.puppetlabs.com/ |
##* https://docs.puppetlabs.com/puppet/3.8/reference/lang_relationships.html#chaining-arrows |
||
=== Puppet templates === |
|||
=== Templates === |
|||
# Write a manifest which utilize templates [[Media:template.tar.gz|solution]] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
#* write a file ''/tmp/testfile'' |
|||
⚫ | |||
⚫ | |||
#* 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: |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
#* 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 |
||
=== Puppet templates === |
|||
=== Node definitions === |
|||
# Write a node definition which includes the pretty ''sshd module'' |
|||
# |
# Write a node definition which includes the pretty ''sshd module'' [[Media:node.pp|solution]] |
||
# Apply the node definition (don't forget the modulepath) |
|||
# Hints: |
# Hints: |
||
#* https://docs.puppetlabs.com/puppet/latest/reference/lang_node_definitions.html |
#* 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: