tests: Create temporary hostkey with proper backup

This commit is contained in:
Jakub Jelen 2021-06-11 11:27:30 +02:00 committed by Jakub Jelen
parent b97a7b0bde
commit d1446017e9
2 changed files with 13 additions and 1 deletions

View file

@ -3,6 +3,8 @@
vars: vars:
__sshd_test_backup_files: __sshd_test_backup_files:
- /etc/ssh/sshd_config - /etc/ssh/sshd_config
- /etc/ssh/ssh_host_rsa_key
- /etc/ssh/ssh_host_rsa_key.pub
tasks: tasks:
- name: "Backup configuration files" - name: "Backup configuration files"
include_tasks: tasks/backup.yml include_tasks: tasks/backup.yml
@ -43,7 +45,15 @@
register: config register: config
- name: List effective configuration using sshd -T (matching) - 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 register: runtime
- name: List effective configuration using sshd -T (non-matching) - name: List effective configuration using sshd -T (non-matching)

View file

@ -4,6 +4,8 @@
__sshd_test_backup_files: __sshd_test_backup_files:
- /etc/ssh/sshd_config - /etc/ssh/sshd_config
- /etc/ssh/sshd_config.d/00-ansible_system_role.conf - /etc/ssh/sshd_config.d/00-ansible_system_role.conf
- /etc/ssh/ssh_host_rsa_key
- /etc/ssh/ssh_host_rsa_key.pub
tasks: tasks:
- name: "Backup configuration files" - name: "Backup configuration files"
include_tasks: tasks/backup.yml include_tasks: tasks/backup.yml