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

120 lines
2.8 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
include_vars: "vars/{{ ansible_distribution | lower }}.yml"
rescue:
- name: read default variable
include_vars: vars/default.yml
2018-11-16 11:44:36 +01:00
2020-03-17 17:25:08 +01:00
#- name: Collect all users and groups allowed to login via ssh
# set_fact:
# sshd_allow_users: '{{ sshd_default_allowed_users + users.keys() | default({}) | sort }}'
# sshd_allow_groups: '{{ sshd_default_allowed_groups + users.keys() | default({}) | sort }}'
- name: Copy sshd configuration
2019-03-06 10:06:08 +01:00
become: yes
template:
2019-04-09 22:13:59 +02:00
src: sshd_config.j2
dest: '/etc/ssh/sshd_config'
owner: root
group: root
mode: 'u=rw,g=r,o=r'
2020-03-17 17:25:08 +01:00
# validate: /usr/sbin/sshd -t -f %s
2019-11-20 12:20:11 +01:00
backup: yes
notify:
2020-03-17 15:43:13 +01:00
- systemctrl restart ssh
2020-03-17 17:25:08 +01:00
- pause:
- name: Generate new ecdsa ssh host key pair if necessary
become: yes
command: ssh-keygen -t ecdsa -f 'ssh_host_ecdsa_key' -P '' -q
args:
chdir: '/etc/ssh/'
creates: 'ssh_host_ecdsa_key.pub'
notify:
2020-03-17 15:43:13 +01:00
- systemctrl restart ssh
when:
- generate_ecdsa_too | bool
- name: Generate new ed25519 ssh host key pair if necessary
2019-03-06 10:06:08 +01:00
become: yes
command: ssh-keygen -t ed25519 -f 'ssh_host_ed25519_key' -P '' -q
args:
chdir: '/etc/ssh/'
creates: 'ssh_host_ed25519_key.pub'
notify:
2020-03-17 15:43:13 +01:00
- systemctrl restart ssh
when:
- ansible_distribution_release != 'wheezy'
- 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-07-17 14:03:00 +02:00
when:
- generate_ecdsa_too | bool
2019-07-17 14:03:00 +02:00
- ansible_distribution_release != 'wheezy'
2019-11-14 11:23:05 +01:00
- do_not_delete_legacy_ssh_keys | bool
- name: Remove unwanted host keys
2019-03-06 10:06:08 +01:00
become: yes
file:
path: '/etc/ssh/ssh_host_{{ item }}_key'
state: absent
with_items:
- ecdsa
- rsa
- dsa
notify:
2020-03-17 15:43:13 +01:00
- systemctrl restart ssh
2019-07-17 14:03:00 +02:00
when:
- not generate_ecdsa_too | bool
2019-07-17 14:03:00 +02:00
- ansible_distribution_release != 'wheezy'
2019-11-14 11:23:05 +01:00
- do_not_delete_legacy_ssh_keys | bool
2019-01-08 14:12:27 +01:00
2019-05-15 13:31:20 +02:00
- name: make sure the correct keys are available
file:
path: '/etc/ssh/ssh_host_{{ item }}_key.pub'
state: absent
2019-03-06 10:06:08 +01:00
become: yes
with_items:
- ecdsa
- rsa
- dsa
notify:
2020-03-17 15:43:13 +01:00
- systemctrl restart ssh
2019-07-17 14:03:00 +02:00
when:
- not generate_ecdsa_too | bool
2019-07-17 14:03:00 +02:00
- ansible_distribution_release != 'wheezy'
2019-11-14 11:23:05 +01:00
- do_not_delete_legacy_ssh_keys | bool
2018-11-16 11:44:36 +01:00
2019-05-15 13:31:20 +02:00
- name: make sure the correct keys are available except ecdsa
file:
path: '/etc/ssh/ssh_host_{{ item }}_key.pub'
state: absent
become: yes
with_items:
- rsa
- dsa
notify:
2020-03-17 15:43:13 +01:00
- systemctrl restart ssh
2019-07-17 14:03:00 +02:00
when:
- generate_ecdsa_too | bool
2019-07-17 14:03:00 +02:00
- ansible_distribution_release != 'wheezy'
2019-11-14 11:23:05 +01:00
- do_not_delete_legacy_ssh_keys | bool