From 46e78f1a15b10ed0becda53de6adc4a99b516053 Mon Sep 17 00:00:00 2001 From: Youngjin Han Date: Wed, 13 May 2020 23:37:30 +0900 Subject: [PATCH] Learning Circle : cidst #5 - initial commit --- youngjin.han/dot-cdist/manifest/init | 9 +++- .../dot-cdist/type/__colourful_file/manifest | 0 .../dot-cdist/type/__my_nginx/manifest | 8 +++ .../dot-cdist/type/__my_nginx/singleton | 0 .../type/__my_nginx_site/gencode-remote | 1 + .../type/__my_nginx_site/gencode-remote~ | 1 + .../dot-cdist/type/__my_nginx_site/manifest | 42 +++++++++++++++ .../dot-cdist/type/__my_nginx_site/manifest~ | 42 +++++++++++++++ youngjin.han/learning-node02-2020.org | 52 +++++++++++++++++++ 9 files changed, 153 insertions(+), 2 deletions(-) mode change 100644 => 100755 youngjin.han/dot-cdist/type/__colourful_file/manifest create mode 100755 youngjin.han/dot-cdist/type/__my_nginx/manifest create mode 100644 youngjin.han/dot-cdist/type/__my_nginx/singleton create mode 100644 youngjin.han/dot-cdist/type/__my_nginx_site/gencode-remote create mode 100644 youngjin.han/dot-cdist/type/__my_nginx_site/gencode-remote~ create mode 100755 youngjin.han/dot-cdist/type/__my_nginx_site/manifest create mode 100755 youngjin.han/dot-cdist/type/__my_nginx_site/manifest~ diff --git a/youngjin.han/dot-cdist/manifest/init b/youngjin.han/dot-cdist/manifest/init index 2bca0b6..5d18418 100644 --- a/youngjin.han/dot-cdist/manifest/init +++ b/youngjin.han/dot-cdist/manifest/init @@ -5,11 +5,16 @@ case "$__target_host" in __motd __timezone Asia/Seoul # __my_computer - __colourful_file --colour yellow +# __colourful_file --colour yellow + __my_nginx_site $__target_host ;; jafo.laptop) __motd __timezone Asia/Seoul - __my_computer +# __my_computer + ;; + *) +# __my_nginx + __my_nginx_site $__target_host ;; esac diff --git a/youngjin.han/dot-cdist/type/__colourful_file/manifest b/youngjin.han/dot-cdist/type/__colourful_file/manifest old mode 100644 new mode 100755 diff --git a/youngjin.han/dot-cdist/type/__my_nginx/manifest b/youngjin.han/dot-cdist/type/__my_nginx/manifest new file mode 100755 index 0000000..90602ab --- /dev/null +++ b/youngjin.han/dot-cdist/type/__my_nginx/manifest @@ -0,0 +1,8 @@ +#!/bin/sh -e + +# update package index +__apt_update_index + +require="__apt_update_index" __package nginx --state=present + + diff --git a/youngjin.han/dot-cdist/type/__my_nginx/singleton b/youngjin.han/dot-cdist/type/__my_nginx/singleton new file mode 100644 index 0000000..e69de29 diff --git a/youngjin.han/dot-cdist/type/__my_nginx_site/gencode-remote b/youngjin.han/dot-cdist/type/__my_nginx_site/gencode-remote new file mode 100644 index 0000000..608991e --- /dev/null +++ b/youngjin.han/dot-cdist/type/__my_nginx_site/gencode-remote @@ -0,0 +1 @@ +echo "sudo service nginx reload" diff --git a/youngjin.han/dot-cdist/type/__my_nginx_site/gencode-remote~ b/youngjin.han/dot-cdist/type/__my_nginx_site/gencode-remote~ new file mode 100644 index 0000000..9adb30b --- /dev/null +++ b/youngjin.han/dot-cdist/type/__my_nginx_site/gencode-remote~ @@ -0,0 +1 @@ +echo "service nginx reload" diff --git a/youngjin.han/dot-cdist/type/__my_nginx_site/manifest b/youngjin.han/dot-cdist/type/__my_nginx_site/manifest new file mode 100755 index 0000000..907798b --- /dev/null +++ b/youngjin.han/dot-cdist/type/__my_nginx_site/manifest @@ -0,0 +1,42 @@ +#!/bin/sh -e + +nginx_config_dir="/etc/nginx/conf.d" +domain="$__object_id" + +__directory /var/www/html/$domain \ + --parents --mode 0644 + +require="__directory//var/www/html/$domain" \ + __file /var/www/html/$domain/index.html \ + --source - --mode 0644 << EOF +Hello Cdist!!! +EOF + +__my_nginx + +# configure nginx +require="__my_nginx" \ + __file "$nginx_config_dir/${domain}.conf" \ + --mode 0644 --source - << EOF +server { + listen 80; + listen [::]:80; + + server_name $domaini; + + access_log /var/log/nginx/access.log; + + client_max_body_size 256m; + + location / { + root /var/www/html/$domain; + index index.html index.htm; + } + + error_page 500 502 503 504 /50x.html; + + location = /50x.html { + root /var/www/html/$domain; + } +} +EOF diff --git a/youngjin.han/dot-cdist/type/__my_nginx_site/manifest~ b/youngjin.han/dot-cdist/type/__my_nginx_site/manifest~ new file mode 100755 index 0000000..56e3762 --- /dev/null +++ b/youngjin.han/dot-cdist/type/__my_nginx_site/manifest~ @@ -0,0 +1,42 @@ +#!/bin/sh -e + +nginx_config_dir="/etc/nginx/conf.d" +domain="$__object_id" + +__directory /var/www/html/$domain \ + --parents --mode 0644 + +require="__directory//var/www/html/$domain" \ + __file /var/www/html/$domain/index.html \ + --source - --mode 0644 << EOF +Hello Cdist!!! +EOF + +__my_nginx + +# configure nginx +require="__my_nginx" \ + __file "$nginx_config_dir/${domain}.conf" \ + --mode 0644 --source - << EOF +server { + listen 80; + listen [::]:80; + + server_name $domain; + + access_log /var/log/nginx/access.log; + + client_max_body_size 256m; + + location / { + root /var/www/html/$domain; + index index.html index.htm; + } + + error_page 500 502 503 504 /50x.html; + + location = /50x.html { + root /var/www/html/$domain; + } +} +EOF diff --git a/youngjin.han/learning-node02-2020.org b/youngjin.han/learning-node02-2020.org index fa69ac2..05d6388 100644 --- a/youngjin.han/learning-node02-2020.org +++ b/youngjin.han/learning-node02-2020.org @@ -1,3 +1,55 @@ +* 2020-05-13 +*** cdist #5: Generating Code & Exploring +**** Lecture content +***** Objective + - Understand how to *generate code* and when to use it + - Exploring explorers +***** Code generation steps + - Modify the previously created type *__my_nginx_site* + - Read about cdist messaging + - If there was a change in the nginx configuration file, reload nginx +***** Explorer steps + - Modify the *__my_nginx_site* type to use the *os explorer* + - Adjust your type to work on Alpine Linux and Debian (or two + other Linux distributions of your choice) + - Set the nginx configuration directory accordingly +***** Documentation + - Explain the following in your cdist.org file + - What is the difference between gencode-remote and the remote code? + - What is the difference between gencode-local and gencode-remote? + - Locate a type that comes with upstream cdist that uses + gencode-local - which one is it? Why does it need gencode-local? +* 2020-05-11 +*** cdist #4: Requirements +**** Lecture content +***** Objective +****** Understand how requirements work +***** DONE Create a new type *__my_nginx* + CLOSED: [2020-05-12 화 02:22] +****** Make it a *singleton* +****** Make it install nginx +****** Configure a host with it +****** Usually nginx is configured includes some files +****** On the target host find out which directory nginx includes +****** We name this directory *nginx_config_dir* +***** DONE Create a new type *__my_nginx_site* + CLOSED: [2020-05-12 화 02:22] +****** Assume the *object_id* is a *domain* +****** In the __my_nginx_site create a file inside the *nginx_config_dir* +****** The filename is *${domain}.conf* +****** When using *__file*, it should *require* the *nginx package* +******* Read about cdist dependencies +****** The file should be a valid nginx configuration +****** The *server name* should be set to the specified domain +****** The *root* directive should point to /var/www/html/DOMAIN +******* (replace DOMAIN with the actual domain) +***** Use both types in the initial manifest to configure the target host +****** Create at least two domains +***** Configure the target host +****** Verify that the configuration files are properly created +***** Delete the nginx package manually on the target host +***** Comment out *__my_nginx* from the initial manifest, keep the *__my_nginx_site* +****** Explain the error that you get (in your cdist.org file) * 2020-05-08 *** cdist #3: type parameters **** Lecture content