Ansible-Linux_Base/roles/base/tasks/core_hostname.yml

64 lines
1.5 KiB
YAML
Raw Normal View History

2021-09-01 17:31:49 -06:00
---
# 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'
2024-01-21 15:00:29 -07:00
line: '127.0.0.1 {{ base_core_hostname }} localhost'
2021-09-01 17:31:49 -06:00
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
2024-11-24 15:24:53 -07:00
- 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
2021-09-01 17:31:49 -06:00
file:
state: absent
path: "{{item}}"
loop:
- /etc/ssh/ssh_host_dsa_key
2024-11-24 15:24:53 -07:00
- /etc/ssh/ssh_host_dsa_key.pub
2021-09-01 17:31:49 -06:00
when: hostname_change.changed
- name: Flush handlers
meta: flush_handlers