aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheqnx <root@heqnx.com>2025-06-24 13:42:17 +0300
committerheqnx <root@heqnx.com>2025-06-24 13:42:17 +0300
commit5b991e1a11faa14822bc2ea27b8dcb949e12ba61 (patch)
tree9aa9cb08715c6ebb1996e5b8a7f28b7aae0ef86e
parent3115a425134f836676da5827582719fe88f0f4ff (diff)
downloadansible-pve-host-5b991e1a11faa14822bc2ea27b8dcb949e12ba61.tar.gz
ansible-pve-host-5b991e1a11faa14822bc2ea27b8dcb949e12ba61.zip
added random hex to hostname
-rw-r--r--inventory.yaml.example2
-rw-r--r--tasks/pve_setup.yaml8
-rw-r--r--templates/hosts.j22
-rw-r--r--vars/main.yaml2
4 files changed, 12 insertions, 2 deletions
diff --git a/inventory.yaml.example b/inventory.yaml.example
index 115fb2b..69081ac 100644
--- a/inventory.yaml.example
+++ b/inventory.yaml.example
@@ -4,7 +4,7 @@ all:
ansible_host: 10.11.12.13
ansible_user: root
ansible_ssh_private_key_file: id_rsa
- hostname: proxmox-ve-test
+ hostname: proxmox
nat_subnet: 10.10.10.0/24
nat_bridge_ip: 10.10.10.1
wg_subnet: 10.13.37.0/24
diff --git a/tasks/pve_setup.yaml b/tasks/pve_setup.yaml
index 9fcea47..9de9489 100644
--- a/tasks/pve_setup.yaml
+++ b/tasks/pve_setup.yaml
@@ -1,3 +1,11 @@
+- name: set hostname to {{ pve_hostname }}
+ copy:
+ content: "{{ pve_hostname }}"
+ dest: /etc/hostname
+ owner: root
+ group: root
+ mode: '0644'
+
- name: generate /etc/hosts from template
template:
src: templates/hosts.j2
diff --git a/templates/hosts.j2 b/templates/hosts.j2
index 3d811dc..647360e 100644
--- a/templates/hosts.j2
+++ b/templates/hosts.j2
@@ -1,5 +1,5 @@
127.0.0.1 localhost
-{{ ansible_host }} {{ hostname }} {{ hostname }}
+{{ ansible_host }} {{ pve_hostname }} {{ pve_hostname }}
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
diff --git a/vars/main.yaml b/vars/main.yaml
index 8c2d0b2..759bcfb 100644
--- a/vars/main.yaml
+++ b/vars/main.yaml
@@ -29,6 +29,8 @@ wireguard_packages:
- iproute2
fail2ban_jail_dir: /etc/fail2ban/jail.d
+random_hex: "{{ lookup('password', '/dev/null', length=8, chars='abcdefghijklmnopqrstuvwxyz0123456789') }}"
+pve_hostname: "{{ hostname }}-{{ random_hex }}"
wg_server_home: /etc/wireguard
wg_peers_home: "{{ wg_server_home }}/peers.d"
wg_ip_file: "{{ wg_server_home }}/ips.txt"