From c1c295cd0f43205b6e6a19f178c167179cc74b99 Mon Sep 17 00:00:00 2001 From: Someone Date: Fri, 4 Oct 2024 13:42:33 +0200 Subject: [PATCH] [roles/base/hostname] set hostname --- roles/base/hostname/defaults/main.yml | 11 +++++++++++ roles/base/hostname/tasks/main.yml | 24 ++++++++++++++++++++++++ roles/base/hostname/templates/hosts.j2 | 14 ++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 roles/base/hostname/defaults/main.yml create mode 100644 roles/base/hostname/tasks/main.yml create mode 100644 roles/base/hostname/templates/hosts.j2 diff --git a/roles/base/hostname/defaults/main.yml b/roles/base/hostname/defaults/main.yml new file mode 100644 index 0000000..bed6790 --- /dev/null +++ b/roles/base/hostname/defaults/main.yml @@ -0,0 +1,11 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +# If not overridden in inventory or as a parameter, this is the value that will be used +# +--- +# allow custom /etc/hosts entries. +hosts_custom_entries: "" diff --git a/roles/base/hostname/tasks/main.yml b/roles/base/hostname/tasks/main.yml new file mode 100644 index 0000000..539bc37 --- /dev/null +++ b/roles/base/hostname/tasks/main.yml @@ -0,0 +1,24 @@ +##################################### +### someone's ansible provisioner ### +##################################### +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# +--- +- name: set hostname + hostname: name="{{inventory_hostname}}" + when: inventory_hostname != "localhost" + + +- name: update /etc/hosts + template: + src: "{{item}}" + dest: "/etc/hosts" + mode: 0755 + owner: "root" + group: "root" + with_first_found: + - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/hosts.j2" + - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/hosts.j2" + - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/hosts.j2" + - "templates/hosts.j2" diff --git a/roles/base/hostname/templates/hosts.j2 b/roles/base/hostname/templates/hosts.j2 new file mode 100644 index 0000000..02d6d10 --- /dev/null +++ b/roles/base/hostname/templates/hosts.j2 @@ -0,0 +1,14 @@ +# +################################################ +### Managed by someone's ansible provisioner ### +################################################ +# Part of: https://git.somenet.org/root/pub/somesible.git +# 2017-2024 by someone +# + +127.0.0.1 {{inventory_hostname}} {{inventory_hostname.split(".")[0]}} l l4 lh lh4 localhost localhost4 localhost.localdomain localhost.localdomain4 ip4-localhost ip4-loopback +::1 {{inventory_hostname}} {{inventory_hostname.split(".")[0]}} l l6 lh lh6 localhost localhost6 localhost.localdomain localhost.localdomain6 ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters + +{{hosts_custom_entries}} -- 2.43.0