2018-03-07 03:28:23 +01:00
|
|
|
---
|
2020-03-17 15:39:07 +01:00
|
|
|
- name: combine sshd variable
|
|
|
|
set_fact:
|
|
|
|
sshd: "{{ _sshd|combine(sshd, recursive=True) }}"
|
|
|
|
|
2019-05-15 11:44:17 +02:00
|
|
|
- include_tasks: versioncheck.yml
|
2019-05-17 12:50:48 +02:00
|
|
|
when: submodules_versioncheck|bool
|
2018-11-16 11:44:36 +01:00
|
|
|
|
2020-03-17 15:39:07 +01:00
|
|
|
- name: set sshd_service variable
|
|
|
|
block:
|
|
|
|
- name: read os specific variable
|
2020-03-27 00:12:00 +01:00
|
|
|
include_vars: "vars/sshd_{{ ansible_distribution | lower }}.yml"
|
2020-03-17 15:39:07 +01:00
|
|
|
rescue:
|
|
|
|
- name: read default variable
|
2020-03-27 00:12:00 +01:00
|
|
|
include_vars: vars/sshd_default.yml
|
2018-11-16 11:44:36 +01:00
|
|
|
|
2020-03-18 11:30:48 +01:00
|
|
|
- name: Collect all users and groups allowed to login via ssh
|
|
|
|
set_fact:
|
|
|
|
sshd_allowed_users: '{{ sshd.allowed_users + users.keys() | default({}) | sort }}'
|
|
|
|
sshd_allowed_groups: '{{ sshd.allowed_groups + users.keys() | default({}) | sort }}'
|
2018-03-16 04:54:02 +01:00
|
|
|
|
2020-03-18 11:50:38 +01:00
|
|
|
- name: Generate new ssh host key pair if necessary
|
2019-04-09 22:03:00 +02:00
|
|
|
become: yes
|
2020-03-18 11:50:38 +01:00
|
|
|
command: ssh-keygen -t ecdsa -f 'ssh_host_{{ item }}_key' -P '' -q
|
2019-04-09 22:03:00 +02:00
|
|
|
args:
|
|
|
|
chdir: '/etc/ssh/'
|
2020-03-18 11:50:38 +01:00
|
|
|
creates: 'ssh_host_{{ item }}_key.pub'
|
2019-04-09 22:03:00 +02:00
|
|
|
notify:
|
2020-03-17 15:43:13 +01:00
|
|
|
- systemctrl restart ssh
|
2020-03-18 11:50:38 +01:00
|
|
|
with_items: "{{ sshd.key_types }}"
|
2019-11-14 11:12:47 +01:00
|
|
|
when:
|
2020-03-18 11:50:38 +01:00
|
|
|
- sshd.manage_key_types | bool
|
2018-03-07 03:28:23 +01:00
|
|
|
|
2019-04-09 22:03:00 +02:00
|
|
|
- name: Remove unwanted host keys
|
|
|
|
become: yes
|
|
|
|
file:
|
|
|
|
path: '/etc/ssh/ssh_host_{{ item }}_key'
|
|
|
|
state: absent
|
|
|
|
with_items:
|
|
|
|
- rsa
|
|
|
|
- dsa
|
|
|
|
notify:
|
2020-03-17 15:43:13 +01:00
|
|
|
- systemctrl restart ssh
|
2019-04-09 22:03:00 +02:00
|
|
|
|
2019-05-15 13:31:20 +02:00
|
|
|
- name: make sure the correct keys are available
|
|
|
|
file:
|
2020-03-18 18:15:23 +01:00
|
|
|
path: '/etc/ssh/ssh_host_{{ item }}_key'
|
2018-03-07 03:28:23 +01:00
|
|
|
state: absent
|
2019-03-06 10:06:08 +01:00
|
|
|
become: yes
|
2018-03-07 03:28:23 +01:00
|
|
|
with_items:
|
2020-03-18 18:15:23 +01:00
|
|
|
- "{{ sshd_key_types_list | difference( sshd.key_types ) }}"
|
2018-03-08 18:48:33 +01:00
|
|
|
notify:
|
2020-03-17 15:43:13 +01:00
|
|
|
- systemctrl restart ssh
|
2018-11-16 11:44:36 +01:00
|
|
|
|
2020-03-18 18:15:23 +01:00
|
|
|
- name: make sure the correct pubkeys are available
|
2019-05-15 13:31:20 +02:00
|
|
|
file:
|
2019-04-09 22:03:00 +02:00
|
|
|
path: '/etc/ssh/ssh_host_{{ item }}_key.pub'
|
|
|
|
state: absent
|
|
|
|
become: yes
|
|
|
|
with_items:
|
2020-03-18 18:15:23 +01:00
|
|
|
- "{{ sshd_key_types_list | difference( sshd.key_types ) }}"
|
2019-04-09 22:03:00 +02:00
|
|
|
notify:
|
2020-03-17 15:43:13 +01:00
|
|
|
- systemctrl restart ssh
|
2020-04-13 17:59:47 +02:00
|
|
|
|
|
|
|
- name: Copy sshd configuration
|
|
|
|
become: yes
|
|
|
|
template:
|
|
|
|
src: sshd_config.j2
|
|
|
|
dest: '/etc/ssh/sshd_config'
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 'u=rw,g=r,o=r'
|
|
|
|
validate: /usr/sbin/sshd -t -f %s
|
|
|
|
backup: yes
|
|
|
|
notify:
|
|
|
|
- systemctrl restart ssh
|