diff --git a/roles/set-hostname/handlers/main.yml b/roles/set-hostname/handlers/main.yml new file mode 100644 index 0000000..d73bfd5 --- /dev/null +++ b/roles/set-hostname/handlers/main.yml @@ -0,0 +1,8 @@ +--- +- name: update hosts + template: + src: hosts.j2 + dest: /etc/hosts + owner: root + group: root + mode: 644 diff --git a/roles/set-hostname/hosts.j2 b/roles/set-hostname/hosts.j2 new file mode 100644 index 0000000..673b1a0 --- /dev/null +++ b/roles/set-hostname/hosts.j2 @@ -0,0 +1,5 @@ +127.0.0.1 localhost {{ hostname }} + +::1 localhost ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters diff --git a/roles/set-hostname/tasks/main.yml b/roles/set-hostname/tasks/main.yml index a42140d..05cc7af 100644 --- a/roles/set-hostname/tasks/main.yml +++ b/roles/set-hostname/tasks/main.yml @@ -1,5 +1,17 @@ --- +- name: Check current hostname + register: cur_hostname + shell: hostname + changed_when: false + +- name: yeet + debug: + msg: "{{ cur_hostname }} - {{ hostname }}" + - name: Set hostname - hostname: - name: "{{ hostname }}" - use: debian + shell: "hostnamectl set-hostname {{ hostname }}" + # hostname: + # name: "{{ hostname }}" + # use: debian + notify: update hosts + when: cur_hostname.stdout != hostname