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

51 lines
1.7 KiB
YAML
Raw Normal View History

---
- name: perform versionscheck
ansible.builtin.include_tasks: versioncheck.yml
2019-05-17 12:50:48 +02:00
when: submodules_versioncheck|bool
2018-11-16 11:44:36 +01:00
2021-03-10 22:34:42 +01:00
- name: load sshd_service variable
ansible.builtin.include_vars: "{{ lookup('first_found', sshd__service_var_path) }}"
2021-03-10 22:34:42 +01:00
- name: install packages
ansible.builtin.include_tasks: packages.yml
2020-03-18 11:30:48 +01:00
- name: Collect all users and groups allowed to login via ssh
set_fact:
2021-03-11 00:21:58 +01:00
sshd__allowed_users: '{{ sshd__allowed_users + users.keys() | default({}) | sort }}'
2020-08-04 15:07:02 +02:00
sshd__allowed_groups: '{{ sshd__allowed_groups + users.keys() | default({}) | sort }}'
2020-09-21 14:51:37 +02:00
- name: "try to get {{ sshd__package }} version"
when: sshd__version_is_above_eight is not defined
block:
- name: Gather the package facts
2021-03-10 22:34:42 +01:00
ansible.builtin.package_facts:
2020-09-21 14:51:37 +02:00
manager: auto
- name: "get package version of {{ sshd__package }}"
2021-03-10 22:34:42 +01:00
ansible.builtin.debug:
2020-09-21 14:51:37 +02:00
msg: "{{ ansible_facts.packages[sshd__package][0].version }}"
- name: set fact sshd__version_is_above_eight
2021-03-10 22:34:42 +01:00
ansible.builtin.set_fact:
2020-09-21 14:51:37 +02:00
sshd__version_is_above_eight: true
when: ansible_facts.packages[sshd__package][0].version is version('8.0', '>=')
rescue:
2021-03-10 22:34:42 +01:00
- ansible.builtin.debug:
2020-09-21 14:51:37 +02:00
msg: "Failed to detect ssh version. Set sshd__version_is_above_eight to true if you want to experience new config features from sshd version 8"
2018-11-16 11:44:36 +01:00
2021-03-10 22:34:42 +01:00
- name: manage ssh host keys
ansible.builtin.include_tasks: keys.yml
2020-04-13 17:59:47 +02:00
2020-08-05 16:33:38 +02:00
- name: Create sshd configuration
2021-03-10 22:34:42 +01:00
become: true
ansible.builtin.template:
src: 'templates/sshd_config.j2'
2020-04-13 17:59:47 +02:00
dest: '/etc/ssh/sshd_config'
owner: root
group: root
mode: 'u=rw,g=r,o=r'
validate: /usr/sbin/sshd -t -f %s
2021-03-10 22:34:42 +01:00
backup: true
2020-04-13 17:59:47 +02:00
notify:
- systemctl restart ssh