hostname: add role

This commit is contained in:
jeltz 2023-04-05 00:18:41 +02:00
parent 454f1d75cb
commit 4ad25f7057
Signed by: jeltz
GPG key ID: 800882B66C0C3326
4 changed files with 53 additions and 0 deletions

8
playbooks/hostname.yml Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env ansible-playbook
---
- hosts:
- pve_network
- vm_network
roles:
- hostname
...

View file

@ -0,0 +1,24 @@
---
hostname__fqdn: "{{ inventory_hostname }}"
hostname__hosts:
- name:
- localhost
- "{{ hostname__fqdn }}"
- "{{ hostname__fqdn.split('.') | first }}"
address:
- 127.0.0.1
- ::1
- name:
- ip6-localhost
- ip6-loopback
address:
- ::1
- name:
- ip6-allnodes
address:
- ff02::1
- name:
- ip6-allrouters
address:
- ff02::2
...

View file

@ -0,0 +1,14 @@
---
- name: Set hostname
hostname:
name: "{{ hostname__fqdn }}"
use: systemd
- name: Configure /etc/hosts
template:
src: hosts.j2
dest: /etc/hosts
owner: root
group: root
mode: u=rw,g=r,o=r
...

View file

@ -0,0 +1,7 @@
{{ ansible_managed | comment }}
{% for item in hostname__hosts %}
{% for addr in item.address %}
{{ addr }} {{ item.name | join(" ") }}
{% endfor %}
{% endfor %}