59 lines
1.6 KiB
YAML
59 lines
1.6 KiB
YAML
|
---
|
||
|
# 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 localhost {{ base_core_hostname }}'
|
||
|
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: Remove ssh certs
|
||
|
file:
|
||
|
state: absent
|
||
|
path: "{{item}}"
|
||
|
loop:
|
||
|
- /etc/ssh/ssh_host_rsa_key
|
||
|
- /etc/ssh/ssh_host_dsa_key
|
||
|
- /etc/ssh/ssh_host_ecdsa_key
|
||
|
- /etc/ssh/ssh_host_ed25519_key
|
||
|
|
||
|
- name: Generate /etc/ssh/ RSA host key
|
||
|
command : ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -C "" -N ""
|
||
|
args:
|
||
|
creates: /etc/ssh/ssh_host_rsa_key
|
||
|
|
||
|
- name: Generate /etc/ssh/ DSA host key
|
||
|
command : ssh-keygen -q -t dsa -f /etc/ssh/ssh_host_dsa_key -C "" -N ""
|
||
|
args:
|
||
|
creates: /etc/ssh/ssh_host_dsa_key
|
||
|
|
||
|
- name: Generate /etc/ssh/ ECDSA host key
|
||
|
command : ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -C "" -N ""
|
||
|
args:
|
||
|
creates: /etc/ssh/ssh_host_ecdsa_key
|
||
|
|
||
|
- name: Generate /etc/ssh/ ED25519 host key
|
||
|
command : ssh-keygen -q -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -C "" -N ""
|
||
|
args:
|
||
|
creates: /etc/ssh/ssh_host_ed25519_key
|
||
|
when: hostname_change.changed
|
||
|
|
||
|
- name: Flush handlers
|
||
|
meta: flush_handlers
|