From 32468df7ff5de85786fdc467de6f655e6986aef0 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Wed, 30 Oct 2024 12:23:44 +0100 Subject: [PATCH] Create needed directories --- tasks/main.yml | 39 ++++++++++++++++++++++++++++++++++++--- vars/main.yml | 3 +++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index d2cbacd..050b098 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -57,10 +57,42 @@ - ssh-server - ssh-server-check-host-keys +- name: stat directories + ansible.builtin.stat: + path: "{{ item }}/" + register: _stat_directories + with_items: + - "{{ ssh_server_config_file | dirname }}" + - "{{ ssh_server_runtime_directory }}" + tags: + - configuration + - ssh-server + - ssh-server-configure + - ssh-server-configure-directories + - ssh-server-configure-directories-stat + +- name: create directories + ansible.builtin.file: + path: "{{ item.item }}" + state: directory + owner: root + group: root + mode: 0755 + with_items: "{{ _stat_directories.results }}" + when: + - item.stat is defined + - not item.stat.exists + tags: + - configuration + - ssh-server + - ssh-server-configure + - ssh-server-configure-directories + - ssh-server-configure-directories-create + - name: update configuration file ansible.builtin.template: - src: etc/ssh/sshd_config.j2 - dest: /etc/ssh/sshd_config + src: "{{ ssh_server_config_file.lstrip('/') }}.j2" + dest: "{{ ssh_server_config_file }}" owner: root group: root mode: 0644 @@ -69,7 +101,8 @@ tags: - configuration - ssh-server - - ssh-server-configuration + - ssh-server-configure + - ssh-server-configure-file - name: start and enable service ansible.builtin.service: diff --git a/vars/main.yml b/vars/main.yml index 5c5e846..5427b57 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -2,3 +2,6 @@ --- ssh_server_dependencies: - openssh-server + +ssh_server_config_file: /etc/ssh/sshd_config +ssh_server_runtime_directory: /run/sshd