Skip to content

Commit

Permalink
feat(motd): new role
Browse files Browse the repository at this point in the history
  • Loading branch information
janikvonrotz committed Feb 14, 2025
1 parent cbd0be6 commit c861188
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
2 changes: 2 additions & 0 deletions plays/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- name: Server setup
hosts: all
roles:
- role: motd
tags: motd
- role: hosts
tags: hosts
- role: timezone
Expand Down
25 changes: 25 additions & 0 deletions roles/motd/README.md
Original file line number Diff line number Diff line change
@@ -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
```
4 changes: 4 additions & 0 deletions roles/motd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Include {{ role_name }} tasks
ansible.builtin.include_tasks: "{{ role_name }}.yml"
when: function is defined
18 changes: 18 additions & 0 deletions roles/motd/tasks/motd.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
2 changes: 1 addition & 1 deletion roles/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
when: nginx_hostname is defined
tags:
- nginx
- nginx_config
- nginx_config

0 comments on commit c861188

Please sign in to comment.