From b8c498df426b610933facb49f458a48456e48072 Mon Sep 17 00:00:00 2001
From: Arthur BOUDREAULT <arthur@lydra.fr>
Date: Wed, 18 Jan 2023 16:45:56 +0100
Subject: [PATCH] refactor: create new play for ssh configuration

---
 roles/ynh_config/defaults/main.yml            |  2 ++
 roles/ynh_config/tasks/main.yml               | 15 ++---------
 roles/ynh_config/tasks/sshd_configuration.yml | 26 +++++++++++++++++++
 3 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 roles/ynh_config/tasks/sshd_configuration.yml

diff --git a/roles/ynh_config/defaults/main.yml b/roles/ynh_config/defaults/main.yml
index 502df6d..8cde258 100644
--- a/roles/ynh_config/defaults/main.yml
+++ b/roles/ynh_config/defaults/main.yml
@@ -38,3 +38,5 @@ ynh_autoupdate:
   # apps: True
   # system: True
   # dest_script: "/usr/local/bin/"
+
+# ynh_ssh_port: "812"
diff --git a/roles/ynh_config/tasks/main.yml b/roles/ynh_config/tasks/main.yml
index b7f44f3..7f5af93 100644
--- a/roles/ynh_config/tasks/main.yml
+++ b/roles/ynh_config/tasks/main.yml
@@ -33,19 +33,8 @@
     - yunohost
     - update
 
-- name: Change SSH port
-  block:
-    - name: Get current SSH setting
-      ansible.builtin.command:
-        yunohost settings get security.ssh.port
-      register: _ynh_ssh_current_value
-      changed_when: False
-
-    - name: Set new SSH setting
-      ansible.builtin.command:
-        "yunohost settings set security.ssh.port -v {{ ynh_ssh_port }}"
-      when: _ynh_ssh_current_value != ynh_ssh_port
-      changed_when: False
+- name: Configure Yunohost SSH port
+  ansible.builtin.include_tasks: sshd_configuration.yml
   when: ynh_ssh_port
   tags:
     - yunohost
diff --git a/roles/ynh_config/tasks/sshd_configuration.yml b/roles/ynh_config/tasks/sshd_configuration.yml
new file mode 100644
index 0000000..3b7970d
--- /dev/null
+++ b/roles/ynh_config/tasks/sshd_configuration.yml
@@ -0,0 +1,26 @@
+---
+#-----------------------------------------------------------------------------#
+# ansible-yunohost allows to deploy Yunohost using Ansible                    #
+# Copyright 2021-present Lydra https://www.lydra.fr/                          #
+#                                                                             #
+# this program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# this program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program. If not, see <http://www.gnu.org/licenses/>.        #
+#                                                                             #
+#-----------------------------------------------------------------------------#
+
+- name: Change SSH port
+  ansible.builtin.command:
+    "yunohost settings set security.ssh.port -v {{ ynh_ssh_port }}"
+  tags:
+    - yunohost
+    - ssh
-- 
GitLab