From 67423daa305baed67a3992c4b846822ccaa53e9c Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Sun, 3 Mar 2024 20:33:25 -0500 Subject: [PATCH] Optimization for MOTD --- galaxy.yml | 2 +- roles/motd/tasks/main.yml | 18 +++++++----------- roles/motd/templates/motd.j2 | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/galaxy.yml b/galaxy.yml index e0e827d..63d5f5d 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: jchristianh name: baseos # The version of the collection. Must be compatible with semantic versioning -version: 1.0.30 +version: 1.0.31 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/roles/motd/tasks/main.yml b/roles/motd/tasks/main.yml index 3b841d9..8cee9ce 100644 --- a/roles/motd/tasks/main.yml +++ b/roles/motd/tasks/main.yml @@ -1,16 +1,12 @@ --- -- name: Format uptime containing days +- name: Format uptime using Jinja ansible.builtin.set_fact: - uptime_formatted: "{{ motd_host_uptime | regex_replace(motd_day_filter, motd_day_filter_repl) }}" - when: - - "'day' in motd_host_uptime" - - -- name: Format uptime not containing days - ansible.builtin.set_fact: - uptime_formatted: "{{ motd_host_uptime | regex_replace(motd_nonday_filter, motd_nonday_filter_repl) }}" - when: - - "'day' not in motd_host_uptime" + uptime_formatted: | + {% if 'day' in motd_host_uptime %} + {{ motd_host_uptime | regex_replace(motd_day_filter, motd_day_filter_repl) }} + {% else %} + {{ motd_host_uptime | regex_replace(motd_nonday_filter, motd_nonday_filter_repl) }} + {% endif %} - name: Update MOTD diff --git a/roles/motd/templates/motd.j2 b/roles/motd/templates/motd.j2 index 7a1cc41..a5c7c04 100644 --- a/roles/motd/templates/motd.j2 +++ b/roles/motd/templates/motd.j2 @@ -19,6 +19,6 @@ IP : {{ motd_host_ip }} CPU : {{ ansible_processor_vcpus }} x {{ ansible_processor[2] }} Memory : {{ "{0:0.2f}".format(ansible_memfree_mb/1024) }} GB free of {{ (ansible_memtotal_mb/1024)|round}} GB Platform : {{ ansible_distribution }} {{ ansible_distribution_version }} {{ ansible_kernel }} -Up : {{ uptime_formatted }} +Up : {{ uptime_formatted | trim }}