From d1446017e926066b0014af80171806ed1edb4be9 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Fri, 11 Jun 2021 11:27:30 +0200 Subject: [PATCH] tests: Create temporary hostkey with proper backup --- tests/tests_config_namespace.yml | 12 +++++++++++- tests/tests_sshd_enable.yml | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/tests_config_namespace.yml b/tests/tests_config_namespace.yml index 54aa4c8..eab0aa7 100644 --- a/tests/tests_config_namespace.yml +++ b/tests/tests_config_namespace.yml @@ -3,6 +3,8 @@ vars: __sshd_test_backup_files: - /etc/ssh/sshd_config + - /etc/ssh/ssh_host_rsa_key + - /etc/ssh/ssh_host_rsa_key.pub tasks: - name: "Backup configuration files" include_tasks: tasks/backup.yml @@ -43,7 +45,15 @@ register: config - name: List effective configuration using sshd -T (matching) - command: sshd -T -Cuser=root,host=localhost,addr=127.0.0.1 + shell: | + set -eu + if set -o | grep pipefail 2>&1 /dev/null ; then + set -o pipefail + fi + if test ! -f /etc/ssh/ssh_host_rsa_key; then + ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -C '' -N '' + fi + sshd -T -Cuser=root,host=localhost,addr=127.0.0.1 register: runtime - name: List effective configuration using sshd -T (non-matching) diff --git a/tests/tests_sshd_enable.yml b/tests/tests_sshd_enable.yml index e4385ce..b076f6b 100644 --- a/tests/tests_sshd_enable.yml +++ b/tests/tests_sshd_enable.yml @@ -4,6 +4,8 @@ __sshd_test_backup_files: - /etc/ssh/sshd_config - /etc/ssh/sshd_config.d/00-ansible_system_role.conf + - /etc/ssh/ssh_host_rsa_key + - /etc/ssh/ssh_host_rsa_key.pub tasks: - name: "Backup configuration files" include_tasks: tasks/backup.yml