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/__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_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-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 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#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#5-messsaging b/sami/my-org-files/cdist.org/cdist#5-messsaging new file mode 100644 index 0000000..16c809f --- /dev/null +++ b/sami/my-org-files/cdist.org/cdist#5-messsaging @@ -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 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