2022-05-02 14:39:00 +02:00
|
|
|
---
|
2022-08-17 16:34:35 +02:00
|
|
|
- name: Create a directory for drop-in configuration snippets
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ sshd_config_file | dirname }}"
|
|
|
|
state: directory
|
|
|
|
mode: "{{ sshd_drop_in_dir_mode }}"
|
|
|
|
when:
|
|
|
|
- sshd_main_config_file is not none
|
2024-03-18 19:20:31 +01:00
|
|
|
- sshd_config_file | dirname == sshd_main_config_file ~ '.d'
|
2022-08-17 16:34:35 +02:00
|
|
|
|
2022-05-02 14:39:00 +02:00
|
|
|
- name: Create the complete configuration file
|
2022-06-03 12:22:17 +02:00
|
|
|
ansible.builtin.template:
|
2022-05-02 14:39:00 +02:00
|
|
|
src: sshd_config.j2
|
|
|
|
dest: "{{ sshd_config_file }}"
|
|
|
|
owner: "{{ sshd_config_owner }}"
|
|
|
|
group: "{{ sshd_config_group }}"
|
|
|
|
mode: "{{ sshd_config_mode }}"
|
|
|
|
validate: >-
|
2022-09-26 16:33:28 +02:00
|
|
|
{% if not __sshd_supports_validate %}
|
|
|
|
true %s
|
|
|
|
{% elif sshd_test_hostkey is defined and sshd_test_hostkey.path is defined %}
|
2022-05-02 14:39:00 +02:00
|
|
|
{{ sshd_binary }} -t -f %s -h {{ sshd_test_hostkey.path }}/rsa_key
|
|
|
|
{% else %}
|
|
|
|
{{ sshd_binary }} -t -f %s
|
|
|
|
{% endif %}
|
|
|
|
backup: "{{ sshd_backup }}"
|
2024-06-21 10:12:02 +02:00
|
|
|
notify: Reload_sshd
|
2022-05-02 14:39:00 +02:00
|
|
|
|
|
|
|
- name: Make sure the include path is present in the main sshd_config
|
2022-06-03 12:30:13 +02:00
|
|
|
ansible.builtin.lineinfile:
|
2022-05-02 14:39:00 +02:00
|
|
|
insertbefore: BOF
|
2022-08-17 16:34:35 +02:00
|
|
|
line: "Include {{ sshd_config_file | dirname }}/*.conf"
|
|
|
|
path: "{{ sshd_main_config_file }}"
|
2022-05-02 14:39:00 +02:00
|
|
|
owner: "{{ sshd_config_owner }}"
|
|
|
|
group: "{{ sshd_config_group }}"
|
|
|
|
mode: "{{ sshd_config_mode }}"
|
|
|
|
validate: >-
|
2022-09-26 16:33:28 +02:00
|
|
|
{% if not __sshd_supports_validate %}
|
|
|
|
true %s
|
|
|
|
{% elif sshd_test_hostkey is defined and sshd_test_hostkey.path is defined %}
|
2022-05-02 14:39:00 +02:00
|
|
|
{{ sshd_binary }} -t -f %s -h {{ sshd_test_hostkey.path }}/rsa_key
|
|
|
|
{% else %}
|
|
|
|
{{ sshd_binary }} -t -f %s
|
|
|
|
{% endif %}
|
|
|
|
backup: "{{ sshd_backup }}"
|
2024-06-21 10:12:02 +02:00
|
|
|
notify: Reload_sshd
|
2022-05-02 14:39:00 +02:00
|
|
|
when:
|
2022-08-17 16:34:35 +02:00
|
|
|
- sshd_main_config_file is not none
|
2024-03-18 19:20:31 +01:00
|
|
|
- sshd_config_file | dirname == sshd_main_config_file ~ '.d'
|