diff --git a/filter_plugins/net_utils.py b/filter_plugins/net_utils.py index 5eecace..cbde396 100644 --- a/filter_plugins/net_utils.py +++ b/filter_plugins/net_utils.py @@ -8,6 +8,7 @@ class FilterModule: def filters(self): return { "remove_domain_suffix": remove_domain_suffix, + "hostname": hostname, "ipaddr_sort": ipaddr_sort, } @@ -17,6 +18,11 @@ def remove_domain_suffix(name): return parent.to_text() +def hostname(fqdn): + name = dns.name.from_text(fqdn) + return name.relativize(name.parent()).to_text() + + def ipaddr_sort(addrs, types, unknown_after=True): check_types = { "global": attrgetter("is_global"), diff --git a/roles/aruba/templates/config.j2 b/roles/aruba/templates/config.j2 index da146f0..5d67987 100644 --- a/roles/aruba/templates/config.j2 +++ b/roles/aruba/templates/config.j2 @@ -1,6 +1,6 @@ {{ ansible_managed | comment(decoration="; ") }} -hostname {{ aruba__hostname | truncate(32) | enquote }} +hostname {{ aruba__hostname | hostname | truncate(32) | enquote }} include-credentials