aboutsummaryrefslogtreecommitdiffstats
path: root/roles/hostname/tasks/main.yml
blob: 02094f0120ed56713c359525b1924ba40ef0e1af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
---
- name: Keep temporary old hostname in /etc/hosts
  lineinfile:
    dest=/etc/hosts
    regexp="^127\.0\.1\.1(.*)"
    line="127.0.1.1{{'\t'}}{{ hostname_name }}{% if hostname_name != hostname_fqdn %}{{'\t'}}{{ hostname_fqdn }}{% endif %}\1"
    state=present
    backup=yes
    backrefs=yes
  when: ansible_hostname != hostname_name
  tags: [configuration,hostname]

- name: Set hostname
  hostname: name={{ hostname_name }}
  when: hostname_name is defined
  tags: [configuration,hostname]

- name: Update /etc/hosts
  lineinfile:
    dest=/etc/hosts
    regexp="^127\.0\.1\.1"
    line="127.0.1.1{{'\t'}}{{ hostname_name }}{% if hostname_name != hostname_fqdn %}{{'\t'}}{{ hostname_fqdn }}{% endif %}"
    state=present
  tags: [configuration,hostname]