In an ansible (ver. 2.10) playbook I would need to invoke the dpkg-reconfigure openssh-server command to recreate SSH server keys.
- name: Create new SSH host's keys
shell: dpkg-reconfigure openssh-server
notify: restart sshd
The problem is that dpkg-reconfigure openssh-server opens a dialog box, and the script get stucked...
Looking into ansible documentation, it seems that dpkg-reconfigure can be managed by debconf module:
Code example related to locales module:
- name: Set default locale to fr_FR.UTF-8
debconf:
name: locales
question: locales/default_environment_locale
value: fr_FR.UTF-8
vtype: select
The question from openssh-server debconf module is: What do you want to do about modified configuration file sshd_config? and the answer would be: keep the local version currently installed.
How could I manage it using ansible debconf module?
I am looking myself for a solution but I haven't found one yet to achieve that with debconf and ansible. The Problem is, debconf has no "selection" in terms of sshd_config. When you look for debconf and preseed (Debian unattended installation) there is simply no Argument where you can specify to keep the current sshd_config.
for example active debconf settings:
These are the questions for the ansible debconf module.
what we are looking for, but thats not possible:
Unfortunately, we have to find a workaround. For my case, I wanted to reconfigure openssh-server on my raspberry pi's Luckily, there is a systemd file on raspbian OS /lib/systemd/system/regenerate_ssh_host_keys.service that does what the name says. To make use of it, just delete the ssh_host_* files and reboot the machine.
If you need to get that for different hosts, you need to find another workaround. Maybe importing new ssh_host key files via ansible, or build a small script.