Compare commits
No commits in common. "3cc31ecb4011255352c69eb63399403cf3b5b4a1" and "665560250f44155d129e3178492f9543e2637f53" have entirely different histories.
3cc31ecb40
...
665560250f
@ -8,7 +8,7 @@ namespace: jchristianh
|
|||||||
name: baseos
|
name: baseos
|
||||||
|
|
||||||
# The version of the collection. Must be compatible with semantic versioning
|
# The version of the collection. Must be compatible with semantic versioning
|
||||||
version: 1.0.28
|
version: 1.0.27
|
||||||
|
|
||||||
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
|
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
|
||||||
readme: README.md
|
readme: README.md
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
---
|
---
|
||||||
motd_motd_file: /etc/motd
|
motd_motd_file : /etc/motd
|
||||||
|
|
||||||
motd_host_ip : "{{ ansible_default_ipv4.address | default('127.0.0.1') }}"
|
|
||||||
motd_host_uptime : "{{ now().replace(microsecond=0) - now().fromtimestamp(now(fmt='%s') | int - ansible_uptime_seconds) }}"
|
|
||||||
|
|
||||||
motd_day_filter : "(.* day[s]?),\\s+(\\d+):(\\d+):(\\d+)"
|
|
||||||
motd_nonday_filter : "(\\d+):(\\d+):(\\d+)"
|
|
||||||
|
|
||||||
|
|
||||||
...
|
...
|
||||||
|
21
roles/motd/scripts/get_uptime.pl
Normal file
21
roles/motd/scripts/get_uptime.pl
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
my $seconds = shift;
|
||||||
|
my $string = sprintf "%02d::%02d::%02d::%02d", (gmtime($seconds))[7,2,1,0];
|
||||||
|
|
||||||
|
# days [0] :: hours [1] :: mins [2] :: seconds [3]
|
||||||
|
my @ups = split(/::/, $string);
|
||||||
|
|
||||||
|
my $return_uptime = "";
|
||||||
|
|
||||||
|
my $i = 0;
|
||||||
|
for (@ups) { $ups[$i] =~ s/^0//g; $i++; }
|
||||||
|
|
||||||
|
$return_uptime .= "$ups[0] days " if $ups[0] != 0;
|
||||||
|
$return_uptime .= "$ups[1] hours " if $ups[1] != 0;
|
||||||
|
$return_uptime .= "$ups[2] minutes " if $ups[2] != 0;
|
||||||
|
# $return_uptime .= "$ups[3] seconds" if $ups[3] != 0;
|
||||||
|
|
||||||
|
print "$return_uptime\n";
|
@ -1,16 +1,20 @@
|
|||||||
---
|
---
|
||||||
- name: Format uptime containing days
|
- name: Set host IP address or set a default
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
uptime_formatted: "{{ motd_host_uptime | regex_replace(motd_day_filter, '\\1 \\2 hours \\3 minutes') }}"
|
host_ip : "{{ ansible_default_ipv4.address | default('127.0.0.1') }}"
|
||||||
when:
|
|
||||||
- "'day' in motd_host_uptime"
|
|
||||||
|
|
||||||
|
|
||||||
- name: Format uptime not containing days
|
- name: Install Perl if needed
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.package:
|
||||||
uptime_formatted: "{{ motd_host_uptime | regex_replace(motd_nonday_filter, '\\1 hours \\2 minutes \\3 seconds') }}"
|
name : perl
|
||||||
when:
|
state : present
|
||||||
- "'day' not in motd_host_uptime"
|
|
||||||
|
|
||||||
|
- name: Get system uptime from script
|
||||||
|
ansible.builtin.script:
|
||||||
|
cmd : "scripts/get_uptime.pl {{ ansible_uptime_seconds }}"
|
||||||
|
register : node_uptime
|
||||||
|
changed_when : false
|
||||||
|
|
||||||
|
|
||||||
- name: Update MOTD
|
- name: Update MOTD
|
||||||
@ -22,3 +26,4 @@
|
|||||||
|
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
|___/
|
|___/
|
||||||
|
|
||||||
|
|
||||||
Host : {{ inventory_hostname }}
|
Host : {{ ansible_fqdn }}
|
||||||
IP : {{ motd_host_ip }}
|
IP : {{ host_ip }}
|
||||||
CPU : {{ ansible_processor_vcpus }} x {{ ansible_processor[2] }}
|
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
|
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 }}
|
Platform : {{ ansible_distribution }} {{ ansible_distribution_version }} {{ ansible_kernel }}
|
||||||
Up : {{ uptime_formatted }}
|
Up : {{ node_uptime.stdout }}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user