1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_sshd.git synced 2024-08-16 11:59:49 +02:00
ansible_role_sshd/tasks/main.yml

77 lines
1.9 KiB
YAML
Raw Normal View History

---
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 }}'
2020-03-18 11:50:38 +01:00
- name: Generate new ssh host key pair if necessary
become: yes
2020-03-18 11:50:38 +01:00
command: ssh-keygen -t ecdsa -f 'ssh_host_{{ item }}_key' -P '' -q
args:
chdir: '/etc/ssh/'
2020-03-18 11:50:38 +01:00
creates: 'ssh_host_{{ item }}_key.pub'
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 }}"
when:
2020-03-18 11:50:38 +01:00
- sshd.manage_key_types | bool
- 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-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'
state: absent
2019-03-06 10:06:08 +01:00
become: yes
with_items:
2020-03-18 18:15:23 +01:00
- "{{ sshd_key_types_list | difference( sshd.key_types ) }}"
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:
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 ) }}"
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