From c861188cfc33d748b70f8759f11ce9565384907d Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Fri, 14 Feb 2025 11:41:20 +0100 Subject: [PATCH] feat(motd): new role --- README.md | 1 + plays/setup.yml | 2 ++ roles/motd/README.md | 25 +++++++++++++++++++++++++ roles/motd/tasks/main.yml | 4 ++++ roles/motd/tasks/motd.yml | 18 ++++++++++++++++++ roles/nginx/tasks/main.yml | 2 +- 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 roles/motd/README.md create mode 100644 roles/motd/tasks/main.yml create mode 100644 roles/motd/tasks/motd.yml diff --git a/README.md b/README.md index 373667d0..70ceb3bb 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ Have a look at the Ansible roles and check how to configure them. | [metabase](roles/metabase/README.md) | Deploy Metabase Docker container. | | [metricbeat](roles/metricbeat/README.md) | Deploy Metricbeat Docker container. | | [moodle](roles/moodle/README.md) | Deploy Moodle container. | +| [motd](roles/motd/README.md) | Set message of the day. | | [mysql](roles/mysql/README.md) | Deploy MySQL database container. | | [n8n](roles/n8n/README.md) | Deploy N8N container. | | [n8n_exporter](roles/n8n_exporter/README.md) | Add nginx config for N8N exporter path. | diff --git a/plays/setup.yml b/plays/setup.yml index e31a78f4..d1f9c154 100644 --- a/plays/setup.yml +++ b/plays/setup.yml @@ -2,6 +2,8 @@ - name: Server setup hosts: all roles: + - role: motd + tags: motd - role: hosts tags: hosts - role: timezone diff --git a/roles/motd/README.md b/roles/motd/README.md new file mode 100644 index 00000000..aa17fad5 --- /dev/null +++ b/roles/motd/README.md @@ -0,0 +1,25 @@ +# motd role + +Set message of the day. + +## Usage + +Configure the role. + +```yml +all: + hosts: + server: + ansible_host: server.example.com + function: Odoo + customer: Your Company + hosting_provider: On-Premise +``` + +And include it in your playbook. + +```yml +- hosts: motd + roles: + - role: motd +``` diff --git a/roles/motd/tasks/main.yml b/roles/motd/tasks/main.yml new file mode 100644 index 00000000..b207fee6 --- /dev/null +++ b/roles/motd/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: Include {{ role_name }} tasks + ansible.builtin.include_tasks: "{{ role_name }}.yml" + when: function is defined diff --git a/roles/motd/tasks/motd.yml b/roles/motd/tasks/motd.yml new file mode 100644 index 00000000..a894cdc0 --- /dev/null +++ b/roles/motd/tasks/motd.yml @@ -0,0 +1,18 @@ +--- +- name: Generate message of the day + shell: | + SERVER_NAME="{{ ansible_host | upper }}" + NAME_LENGTH=$(echo -n "$SERVER_NAME" | wc -c) + BOX_WIDTH=$((NAME_LENGTH + 4)) + printf '%*s\n' "$BOX_WIDTH" | tr ' ' '#' + printf '# %s #\n' "$SERVER_NAME" + printf '%*s\n' "$BOX_WIDTH" | tr ' ' '#' + echo "Function: {{ function }}" + echo "Customer: {{ customer }}" + echo "Hosting-Provider: {{ hosting_provider }}" + register: motd_content + +- name: Set custom MOTD + copy: + dest: /etc/motd + content: "{{ motd_content.stdout }}" diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml index 884df939..a408b92d 100644 --- a/roles/nginx/tasks/main.yml +++ b/roles/nginx/tasks/main.yml @@ -10,4 +10,4 @@ when: nginx_hostname is defined tags: - nginx - - nginx_config \ No newline at end of file + - nginx_config