-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathhostname.sls
More file actions
67 lines (60 loc) · 2.35 KB
/
Copy pathhostname.sls
File metadata and controls
67 lines (60 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# set the hostname in the kernel, this is needed for Red Hat systems
# and does not hurt in others
kernel_hostname:
cmd.run:
- name: sysctl kernel.hostname={{ grains['hostname'] }}
- unless: sysctl --values kernel.hostname | grep -w {{ grains['hostname'] }}
# set the hostname in userland. There is no consensus among distros
# but Debian prefers the short name, SUSE demands the short name,
# Red Hat suggests the FQDN but works with the short name.
# Bottom line: short name is used here
temporary_hostname:
cmd.run:
{% if grains['init'] == 'systemd' %}
- name: hostnamectl set-hostname {{ grains['hostname'] }}
{% else %}
- name: hostname {{ grains['hostname'] }}
{% endif %}
# set the hostname in the filesystem, matching the temporary hostname
permanent_hostname:
file.managed:
- name: /etc/hostname
- contents: {{ grains['hostname'] }}
# /etc/HOSTNAME is supposed to always contain the FQDN
legacy_permanent_hostname:
file.managed:
- name: /etc/HOSTNAME
- follow_symlinks: False
- contents: {{ grains['hostname'] }}.{{ grains['domain'] }}
change_searchlist_netconfig:
file.replace:
- name: /etc/sysconfig/network/config
- pattern: NETCONFIG_DNS_STATIC_SEARCHLIST=.*
- repl: NETCONFIG_DNS_STATIC_SEARCHLIST="{{ grains['domain'] }}"
- onlyif: test -f /etc/sysconfig/network/config && command -v netconfig
netconfig_update:
cmd.run:
- name: netconfig update -f
- require:
- file: change_searchlist_netconfig
- onlyif: test -f /etc/sysconfig/network/config && command -v netconfig
change_searchlist:
file.append:
- name: /etc/resolv.conf
- text: search {{ grains['domain'] }}
- unless: test -f /etc/sysconfig/network/config && command -v netconfig
# set the hostname and FQDN name in /etc/hosts
# this is not needed if a proper DNS server is in place, but when using avahi this
# might not be the case. The script tries to to use real IP addresses in order not
# to break round-robin DNS resolution and only uses 127.0.1.1 as a last resort.
{% if grains['use_avahi'] %}
hosts_file_hack:
cmd.script:
- name: salt://default/set_ip_in_etc_hosts.py
{% if grains.get('ipv6')['enable'] %}
- args: "{{ grains['hostname'] }} {{ grains['domain'] }}"
{% else %}
- args: "--no-ipv6 {{ grains['hostname'] }} {{ grains['domain'] }}"
{% endif %}
- template: jinja
{% endif %}