--- # file: roles/base/tasks/core_hostname.yml - name: Ensure system hostname hostname: name: "{{ base_core_hostname }}" when: base_core_hostname != "" and base_core_hostname != ansible_facts['nodename'] register: hostname_change notify: Reboot Host - block: - name: Ensure hostname is set in /etc/hosts lineinfile: dest: /etc/hosts regexp: '^127\.0\.0\.1[ \t]+localhost' line: '127.0.0.1 {{ base_core_hostname }} localhost' state: present - name: Ensure hostname is set in /etc/hosts lineinfile: dest: /etc/hosts regexp: '^127\.0\.1\.1[ \t]' line: '127.0.1.1 {{ base_core_hostname }}' state: present - name: Generate /etc/ssh/ RSA host key openssh_keypair: path: /etc/ssh/ssh_host_rsa_key owner: root state: present type: rsa regenerate: full_idempotence force: yes - name: Generate /etc/ssh/ ECDSA host key openssh_keypair: path: /etc/ssh/ssh_host_rsa_key owner: root state: present type: ecdsa regenerate: full_idempotence force: yes - name: Generate /etc/ssh/ ED25519 host key openssh_keypair: path: /etc/ssh/ssh_host_rsa_key owner: root state: present type: ed25519 regenerate: full_idempotence force: yes - name: Remove /etc/ssh/ DSA host key file: state: absent path: "{{item}}" loop: - /etc/ssh/ssh_host_dsa_key - /etc/ssh/ssh_host_dsa_key.pub when: hostname_change.changed - name: Flush handlers meta: flush_handlers