From 3045a40ba77dee48aab90567a5acb06e50bca4b0 Mon Sep 17 00:00:00 2001 From: samuel Date: Tue, 12 May 2020 12:06:57 +0200 Subject: [PATCH 1/5] adding org files --- sami/.gitignore | 21 +++++++ sami/my-cdist/.cdist/files/motd | 1 + sami/my-cdist/.cdist/manifest/init | 15 +++++ .../.cdist/type/__my_computer/manifest | 10 ++- sami/my-org-files/#cdist.org# | 63 +++++++++++++++++++ sami/my-org-files/cdist.org/cdist#1-intro.org | 38 +++++++++++ sami/my-org-files/cdist.org/cdist#2-type.org | 24 +++++++ sami/my-org-files/cdist.org/cdist.org | 15 +++++ 8 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 sami/.gitignore create mode 100644 sami/my-cdist/.cdist/files/motd create mode 100644 sami/my-org-files/#cdist.org# create mode 100644 sami/my-org-files/cdist.org/cdist#1-intro.org create mode 100644 sami/my-org-files/cdist.org/cdist#2-type.org create mode 100644 sami/my-org-files/cdist.org/cdist.org diff --git a/sami/.gitignore b/sami/.gitignore new file mode 100644 index 0000000..72e7b61 --- /dev/null +++ b/sami/.gitignore @@ -0,0 +1,21 @@ + +# Created by https://www.gitignore.io/api/linux +# Edit at https://www.gitignore.io/?templates=linux + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# End of https://www.gitignore.io/api/linux + diff --git a/sami/my-cdist/.cdist/files/motd b/sami/my-cdist/.cdist/files/motd new file mode 100644 index 0000000..7ce6bf3 --- /dev/null +++ b/sami/my-cdist/.cdist/files/motd @@ -0,0 +1 @@ +my message of the day diff --git a/sami/my-cdist/.cdist/manifest/init b/sami/my-cdist/.cdist/manifest/init index e69de29..8f12e3b 100644 --- a/sami/my-cdist/.cdist/manifest/init +++ b/sami/my-cdist/.cdist/manifest/init @@ -0,0 +1,15 @@ +case "$__target_host" in + localhost) + #target is configured with cdist + __file /etc/cdist-configured + + # motd from th file directory + __motd --source "$__files/motd" + + __timezone Europe/Zurich + + # types to be used + __my_computer +;; +esac + diff --git a/sami/my-cdist/.cdist/type/__my_computer/manifest b/sami/my-cdist/.cdist/type/__my_computer/manifest index 07320cd..662e44c 100755 --- a/sami/my-cdist/.cdist/type/__my_computer/manifest +++ b/sami/my-cdist/.cdist/type/__my_computer/manifest @@ -19,7 +19,15 @@ # # # Ensure sipcalc is present -# + __package sipcalc --state present +__package emacs --state present + +__package firefox --state present + +__package nmap --state present + +__package zsh --state present + diff --git a/sami/my-org-files/#cdist.org# b/sami/my-org-files/#cdist.org# new file mode 100644 index 0000000..cef418c --- /dev/null +++ b/sami/my-org-files/#cdist.org# @@ -0,0 +1,63 @@ + + + + + +*** cdist #1: Introduction +**** Lecture content +***** Objective +****** Begin to use cdist +***** Steps +****** Checkout cdist quickstart https://www.cdi.st/manual/latest/cdist-quickstart.html +****** Install cdist locally +****** Create a new cdist configuration directory in ~/ungleich-learning-circle/USERNAME/dot-cdist +****** Create an empty initial manifest ("use touch") +****** Commit that status +****** Ensure that you can login as root to localhost via ssh without a password +****** Configure cdist to configures the motd of your localhost +******* Ensure you have a case block matching on $__target_host +******* Use the -c parameter to cdist to specify the configuration directory +******* Use the -vv parameter to get more verbose output +******* Search for / understand what MOTD stands for +****** Configure cdist to create the file /etc/cdist-configured +****** Configure cdist to setup the timezone on your local computer +****** Configure cdist to ensure emacs is installed +****** Ensure that in the end all changes are committed in your repository + + + + + + + + + + + + + + + + + + + + + + + +* cdist #5: Generating Code & Exploring + +* Understanding how to generate code and when to use it +** define gencode-remote script: ~/.cdist/type/__nginx_site. After manifest is applied it should restart services so configuration is active. Our gencode-remote looks like echo "service nginx restart" + +* Modify the previously created type *__my_nginx_site* +** We modify the previously created type so that the gencode-remote script reacts accordingly +- echo "if_configurationfile_changes" >> "$__messages_out" + +* Read about cdist messaging +** cdist has a simple but powerful way of allowing communication between the initial manifest and types as well as types and types. +* What is the difference between gencode-local and gencode-remote? + +** gencode-remote used to generate code to be executed on the target host +** gencode-local used to generate code to be executed on the source host \ No newline at end of file diff --git a/sami/my-org-files/cdist.org/cdist#1-intro.org b/sami/my-org-files/cdist.org/cdist#1-intro.org new file mode 100644 index 0000000..89f31bc --- /dev/null +++ b/sami/my-org-files/cdist.org/cdist#1-intro.org @@ -0,0 +1,38 @@ +*** cdist #1: Introduction +**** Lecture content +***** Objective +****** Begin to use cdist +***** Steps +****** Install cdist locally https://www.cdi.st/manual/latest/cdist-quickstart.html +****** Create a new cdist configuration directory in ~/ungleich-learning-circle/USERNAME/dot-cdist +****** Create an empty initial manifest +****** Commit that status +****** Ensure that you can login as root to localhost via ssh without a password +****** Configure cdist to configures the motd of your localhost +******* Ensure you have a case block matching on $__target_host +******* Use the -c parameter to cdist to specify the configuration directory +******* Use the -vv parameter to get more verbose output +****** Configure cdist to create the file /etc/cdist-configured +****** Configure cdist to setup the timezone on your local computer +****** Configure cdist to ensure emacs is installed +****** Ensure that in the end all changes are committed in your repository + +* init.file +- sami@cdist/manifest$ cat init +case "$__target_host" in + localhost) + #target is configured with cdist + __file /etc/cdist-configured + + # motd from th file directory + __motd --source "$__files/motd" + + __timezone Europe/Zurich + + +;; +esac + + +* Types manifest for installing packages or insuring that packages are installed +- __package emacs --state present diff --git a/sami/my-org-files/cdist.org/cdist#2-type.org b/sami/my-org-files/cdist.org/cdist#2-type.org new file mode 100644 index 0000000..614d705 --- /dev/null +++ b/sami/my-org-files/cdist.org/cdist#2-type.org @@ -0,0 +1,24 @@ +*** cdist #2: Your first cdist type +**** Lecture content +***** Objective +****** Begin to understand how cdist types function +******* Types are the main component of cdist and define functionality. If you use cdist, you'll write a type for every functionality you would like to use. +***** Steps +****** Create a new type named `__my_computer` + - Mark the type as a singleton type (If a type is flagged as a singleton, it may be used only once per host.) + - Create a `manifest` file in it + - Use this type to install the following packages: zsh, mosh, emacs, nmap, sipcalc + - Edit the *initial manifest* and use **__my_computer** - Here we have to simply add __my_computer in the types file + **localhost** + - Match using the $__target_host variable +****** Modify your type to use a *for loop* to install the packages +****** Deploy / manage your ~/.emacs file in this type + - Ensure that permissions and ownership are correct +****** Use different *verbosity* levels when configuring +****** Ensure that all your changes are committed and pushed in your ungleich-learning-circle repository + - Use magit inside emacs for that +***** Documentation steps to be done in cdist.org + - Create a new org document named `cdist.org` in the safind . -name "~/.emacs"me folder as the learning.org file + - Explain the difference between a singleton and non-singleton type + - Explain the difference between the different verbosity levels + - Document (copy&paste) some of the cdist runs in a "log" section```find . -name "~/.emacs" diff --git a/sami/my-org-files/cdist.org/cdist.org b/sami/my-org-files/cdist.org/cdist.org new file mode 100644 index 0000000..a6bb386 --- /dev/null +++ b/sami/my-org-files/cdist.org/cdist.org @@ -0,0 +1,15 @@ +* cdist #5: Generating Code & Exploring + +* Understanding how to generate code and when to use it +** define gencode-remote script: ~/.cdist/type/__nginx_site. After manifest is applied it should restart services so configuration is active. Our gencode-remote looks like echo "service nginx restart" + +* Modify the previously created type *__my_nginx_site* +** We modify the previously created type so that the gencode-remote script reacts accordingly +- echo "if_configurationfile_changes" >> "$__messages_out" + +* Read about cdist messaging +** cdist has a simple but powerful way of allowing communication between the initial manifest and types as well as types and types. +* What is the difference between gencode-local and gencode-remote? + +** gencode-remote used to generate code to be executed on the target host +** gencode-local used to generate code to be executed on the source host \ No newline at end of file From 74b57875d9dfc646c948cd03d7e1ac8cde4a94ab Mon Sep 17 00:00:00 2001 From: samuel Date: Tue, 12 May 2020 12:12:50 +0200 Subject: [PATCH 2/5] removing tep files --- sami/my-org-files/#cdist.org# | 63 ------------------------- sami/my-org-files/.git.ignore | 0 sami/my-org-files/cdist.org/#cdist.org# | 15 ++++++ 3 files changed, 15 insertions(+), 63 deletions(-) delete mode 100644 sami/my-org-files/#cdist.org# create mode 100644 sami/my-org-files/.git.ignore create mode 100644 sami/my-org-files/cdist.org/#cdist.org# diff --git a/sami/my-org-files/#cdist.org# b/sami/my-org-files/#cdist.org# deleted file mode 100644 index cef418c..0000000 --- a/sami/my-org-files/#cdist.org# +++ /dev/null @@ -1,63 +0,0 @@ - - - - - -*** cdist #1: Introduction -**** Lecture content -***** Objective -****** Begin to use cdist -***** Steps -****** Checkout cdist quickstart https://www.cdi.st/manual/latest/cdist-quickstart.html -****** Install cdist locally -****** Create a new cdist configuration directory in ~/ungleich-learning-circle/USERNAME/dot-cdist -****** Create an empty initial manifest ("use touch") -****** Commit that status -****** Ensure that you can login as root to localhost via ssh without a password -****** Configure cdist to configures the motd of your localhost -******* Ensure you have a case block matching on $__target_host -******* Use the -c parameter to cdist to specify the configuration directory -******* Use the -vv parameter to get more verbose output -******* Search for / understand what MOTD stands for -****** Configure cdist to create the file /etc/cdist-configured -****** Configure cdist to setup the timezone on your local computer -****** Configure cdist to ensure emacs is installed -****** Ensure that in the end all changes are committed in your repository - - - - - - - - - - - - - - - - - - - - - - - -* cdist #5: Generating Code & Exploring - -* Understanding how to generate code and when to use it -** define gencode-remote script: ~/.cdist/type/__nginx_site. After manifest is applied it should restart services so configuration is active. Our gencode-remote looks like echo "service nginx restart" - -* Modify the previously created type *__my_nginx_site* -** We modify the previously created type so that the gencode-remote script reacts accordingly -- echo "if_configurationfile_changes" >> "$__messages_out" - -* Read about cdist messaging -** cdist has a simple but powerful way of allowing communication between the initial manifest and types as well as types and types. -* What is the difference between gencode-local and gencode-remote? - -** gencode-remote used to generate code to be executed on the target host -** gencode-local used to generate code to be executed on the source host \ No newline at end of file diff --git a/sami/my-org-files/.git.ignore b/sami/my-org-files/.git.ignore new file mode 100644 index 0000000..e69de29 diff --git a/sami/my-org-files/cdist.org/#cdist.org# b/sami/my-org-files/cdist.org/#cdist.org# new file mode 100644 index 0000000..16c809f --- /dev/null +++ b/sami/my-org-files/cdist.org/#cdist.org# @@ -0,0 +1,15 @@ +cdist #5: Generating Code & Exploring + +* Understanding how to generate code and when to use it +** define gencode-remote script: ~/.cdist/type/__nginx_site. After manifest is applied it should restart services so configuration is active. Our gencode-remote looks like echo "service nginx restart" + +* Modify the previously created type *__my_nginx_site* +** We modify the previously created type so that the gencode-remote script reacts accordingly +- echo "if_configurationfile_changes" >> "$__messages_out" + +* Read about cdist messaging +** cdist has a simple but powerful way of allowing communication between the initial manifest and types as well as types and types. +* What is the difference between gencode-local and gencode-remote? + +** gencode-remote used to generate code to be executed on the target host +** gencode-local used to generate code to be executed on the source host From fc49f8c4bdc8254ee4d86247d6c65c13470dc7d7 Mon Sep 17 00:00:00 2001 From: Samuel Hailu Date: Tue, 12 May 2020 12:13:57 +0200 Subject: [PATCH 3/5] Delete #cdist.org# --- sami/my-org-files/cdist.org/#cdist.org# | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 sami/my-org-files/cdist.org/#cdist.org# diff --git a/sami/my-org-files/cdist.org/#cdist.org# b/sami/my-org-files/cdist.org/#cdist.org# deleted file mode 100644 index 16c809f..0000000 --- a/sami/my-org-files/cdist.org/#cdist.org# +++ /dev/null @@ -1,15 +0,0 @@ -cdist #5: Generating Code & Exploring - -* Understanding how to generate code and when to use it -** define gencode-remote script: ~/.cdist/type/__nginx_site. After manifest is applied it should restart services so configuration is active. Our gencode-remote looks like echo "service nginx restart" - -* Modify the previously created type *__my_nginx_site* -** We modify the previously created type so that the gencode-remote script reacts accordingly -- echo "if_configurationfile_changes" >> "$__messages_out" - -* Read about cdist messaging -** cdist has a simple but powerful way of allowing communication between the initial manifest and types as well as types and types. -* What is the difference between gencode-local and gencode-remote? - -** gencode-remote used to generate code to be executed on the target host -** gencode-local used to generate code to be executed on the source host From ec100635e160ce809bbf0f1c18a7aed5223f9a14 Mon Sep 17 00:00:00 2001 From: samuel Date: Tue, 12 May 2020 12:17:02 +0200 Subject: [PATCH 4/5] renaming --- sami/my-org-files/cdist.org/{#cdist.org# => cdist#5-messsaging} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sami/my-org-files/cdist.org/{#cdist.org# => cdist#5-messsaging} (100%) diff --git a/sami/my-org-files/cdist.org/#cdist.org# b/sami/my-org-files/cdist.org/cdist#5-messsaging similarity index 100% rename from sami/my-org-files/cdist.org/#cdist.org# rename to sami/my-org-files/cdist.org/cdist#5-messsaging From 7b39b906fb48ddded2441b1881b12231453ffda8 Mon Sep 17 00:00:00 2001 From: samuel Date: Fri, 15 May 2020 17:01:31 +0200 Subject: [PATCH 5/5] all --- .../.cdist/type/__all_in_one/manifest | 30 +++++++++++++++++++ .../type/__all_in_one/parameter/boolean | 1 + .../type/__all_in_one/parameter/optional | 0 .../.cdist/type/__all_in_one/singleton | 0 .../.cdist/type/__colorful_file/manifest | 24 +++++++++++++++ .../type/__colorful_file/parameter/optional | 1 + .../__my_firewall/explorer/package-ensured | 9 ++++++ .../.cdist/type/__my_firewall/manifest | 0 .../type/__my_firewall/parameter/required | 1 + 9 files changed, 66 insertions(+) create mode 100644 sami/my-cdist/.cdist/type/__all_in_one/manifest create mode 100644 sami/my-cdist/.cdist/type/__all_in_one/parameter/boolean create mode 100644 sami/my-cdist/.cdist/type/__all_in_one/parameter/optional create mode 100644 sami/my-cdist/.cdist/type/__all_in_one/singleton create mode 100644 sami/my-cdist/.cdist/type/__colorful_file/manifest create mode 100644 sami/my-cdist/.cdist/type/__colorful_file/parameter/optional create mode 100644 sami/my-cdist/.cdist/type/__my_firewall/explorer/package-ensured create mode 100644 sami/my-cdist/.cdist/type/__my_firewall/manifest create mode 100644 sami/my-cdist/.cdist/type/__my_firewall/parameter/required diff --git a/sami/my-cdist/.cdist/type/__all_in_one/manifest b/sami/my-cdist/.cdist/type/__all_in_one/manifest new file mode 100644 index 0000000..1869a29 --- /dev/null +++ b/sami/my-cdist/.cdist/type/__all_in_one/manifest @@ -0,0 +1,30 @@ +os="$(cat "$__global/explorer/os")" +case "$os" in + fedora) + __package nmap-ncat --state present + __package wireshark-cli --state present + +;; + debian) + + __package netcat --state present + __package tshark --state present + + + alpine) + + __package netcat-openbsd --state present + __package tshark --state present +;; + + +*) + echo "Don't know how to manage packages on: $os" >&2 + exit 1 + ;; +esac + + + __package socat --state present __package sipcalc --state present __package sudo --state present + + diff --git a/sami/my-cdist/.cdist/type/__all_in_one/parameter/boolean b/sami/my-cdist/.cdist/type/__all_in_one/parameter/boolean new file mode 100644 index 0000000..b776efe --- /dev/null +++ b/sami/my-cdist/.cdist/type/__all_in_one/parameter/boolean @@ -0,0 +1 @@ +--with-x diff --git a/sami/my-cdist/.cdist/type/__all_in_one/parameter/optional b/sami/my-cdist/.cdist/type/__all_in_one/parameter/optional new file mode 100644 index 0000000..e69de29 diff --git a/sami/my-cdist/.cdist/type/__all_in_one/singleton b/sami/my-cdist/.cdist/type/__all_in_one/singleton new file mode 100644 index 0000000..e69de29 diff --git a/sami/my-cdist/.cdist/type/__colorful_file/manifest b/sami/my-cdist/.cdist/type/__colorful_file/manifest new file mode 100644 index 0000000..746ea5e --- /dev/null +++ b/sami/my-cdist/.cdist/type/__colorful_file/manifest @@ -0,0 +1,24 @@ +# required parameter +#servername="$(cat "$__object/parameter/servername")" + +# optional parameter +if [ -f "$__object/parameter/optional" ]; then + logdirectory="$(cat "$__object/parameter/optional")" +fi + +# optional parameter with predefined default +#loglevel="$(cat "$__object/parameter/loglevel")" + +# boolean parameter +#if [ -f "$__object/parameter/use_ssl" ]; then + # file exists -> True + # do some fancy ssl stuff +#fi + +# parameter with multiple values +#if [ -f "$__object/parameter/server_colorful" ]; then + # for alias in $(cat "$__object/parameter/server_alias"); do + # echo $alias > /some/where/useful + #done +#fi + diff --git a/sami/my-cdist/.cdist/type/__colorful_file/parameter/optional b/sami/my-cdist/.cdist/type/__colorful_file/parameter/optional new file mode 100644 index 0000000..7169fdc --- /dev/null +++ b/sami/my-cdist/.cdist/type/__colorful_file/parameter/optional @@ -0,0 +1 @@ +colorful diff --git a/sami/my-cdist/.cdist/type/__my_firewall/explorer/package-ensured b/sami/my-cdist/.cdist/type/__my_firewall/explorer/package-ensured new file mode 100644 index 0000000..0a37062 --- /dev/null +++ b/sami/my-cdist/.cdist/type/__my_firewall/explorer/package-ensured @@ -0,0 +1,9 @@ +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +# Expect dpkg failing, if package is not known / installed +dpkg -s "$name" 2>/dev/null || exit 0 + diff --git a/sami/my-cdist/.cdist/type/__my_firewall/manifest b/sami/my-cdist/.cdist/type/__my_firewall/manifest new file mode 100644 index 0000000..e69de29 diff --git a/sami/my-cdist/.cdist/type/__my_firewall/parameter/required b/sami/my-cdist/.cdist/type/__my_firewall/parameter/required new file mode 100644 index 0000000..f73f309 --- /dev/null +++ b/sami/my-cdist/.cdist/type/__my_firewall/parameter/required @@ -0,0 +1 @@ +file