From 428aaf7e654e9c6e109663aa32b25d129c3c5cab Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 28 Jan 2020 11:04:36 -0800 Subject: [PATCH] Keep SSH authorized keys in ansible-test setup. --- .../fragments/ansible-test-preserve-remote-authorized-keys.yml | 2 ++ test/lib/ansible_test/_data/setup/remote.sh | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-test-preserve-remote-authorized-keys.yml diff --git a/changelogs/fragments/ansible-test-preserve-remote-authorized-keys.yml b/changelogs/fragments/ansible-test-preserve-remote-authorized-keys.yml new file mode 100644 index 00000000000..8a6a03d8a06 --- /dev/null +++ b/changelogs/fragments/ansible-test-preserve-remote-authorized-keys.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test now preserves existing SSH authorized keys when provisioning a remote host diff --git a/test/lib/ansible_test/_data/setup/remote.sh b/test/lib/ansible_test/_data/setup/remote.sh index 4cb8a233008..9d37602b748 100644 --- a/test/lib/ansible_test/_data/setup/remote.sh +++ b/test/lib/ansible_test/_data/setup/remote.sh @@ -90,7 +90,8 @@ if [ ! -f "${HOME}/.ssh/id_rsa.pub" ]; then chmod 0600 "${HOME}/.ssh/id_rsa.new" sed 's/\(BEGIN\|END\) PRIVATE KEY/\1 RSA PRIVATE KEY/' "${HOME}/.ssh/id_rsa" > "${HOME}/.ssh/id_rsa.new" mv "${HOME}/.ssh/id_rsa.new" "${HOME}/.ssh/id_rsa" - cp "${HOME}/.ssh/id_rsa.pub" "${HOME}/.ssh/authorized_keys" + cat "${HOME}/.ssh/id_rsa.pub" >> "${HOME}/.ssh/authorized_keys" + chmod 0600 "${HOME}/.ssh/authorized_keys" for key in /etc/ssh/ssh_host_*_key.pub; do pk=$(cat "${key}") echo "localhost ${pk}" >> "${HOME}/.ssh/known_hosts"