hostname: add role
This commit is contained in:
parent
454f1d75cb
commit
4ad25f7057
4 changed files with 53 additions and 0 deletions
8
playbooks/hostname.yml
Executable file
8
playbooks/hostname.yml
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env ansible-playbook
|
||||||
|
---
|
||||||
|
- hosts:
|
||||||
|
- pve_network
|
||||||
|
- vm_network
|
||||||
|
roles:
|
||||||
|
- hostname
|
||||||
|
...
|
24
roles/hostname/defaults/main.yml
Normal file
24
roles/hostname/defaults/main.yml
Normal 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
|
||||||
|
...
|
14
roles/hostname/tasks/main.yml
Normal file
14
roles/hostname/tasks/main.yml
Normal 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
|
||||||
|
...
|
7
roles/hostname/templates/hosts.j2
Normal file
7
roles/hostname/templates/hosts.j2
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
|
{% for item in hostname__hosts %}
|
||||||
|
{% for addr in item.address %}
|
||||||
|
{{ addr }} {{ item.name | join(" ") }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
Loading…
Reference in a new issue