diff --git a/roles/edpm_ssh_known_hosts/molecule/default/molecule.yml b/roles/edpm_ssh_known_hosts/molecule/default/molecule.yml index 39ab82197..17a158621 100644 --- a/roles/edpm_ssh_known_hosts/molecule/default/molecule.yml +++ b/roles/edpm_ssh_known_hosts/molecule/default/molecule.yml @@ -25,6 +25,7 @@ provisioner: allovercloud: hosts: instance: + ansible_port: 2222 canonical_hostname: centos.localdomain ctlplane_hostname: centos.ctlplane.localdomain ctlplane_ip: 10.0.0.1 diff --git a/roles/edpm_ssh_known_hosts/molecule/default/tests/test_default.py b/roles/edpm_ssh_known_hosts/molecule/default/tests/test_default.py index a9b19165a..2d7b58538 100644 --- a/roles/edpm_ssh_known_hosts/molecule/default/tests/test_default.py +++ b/roles/edpm_ssh_known_hosts/molecule/default/tests/test_default.py @@ -25,9 +25,9 @@ def test_ssh_host_keys(host): expected = [ - '10.0.0.1,centos.ctlplane.localdomain,10.0.1.1,centos.internalapi.localdomain,centos.localdomain,instance* ssh-rsa AAAATESTRSA', - '10.0.0.1,centos.ctlplane.localdomain,10.0.1.1,centos.internalapi.localdomain,centos.localdomain,instance* ssh-ed25519 AAAATESTED', - '10.0.0.1,centos.ctlplane.localdomain,10.0.1.1,centos.internalapi.localdomain,centos.localdomain,instance* ecdsa-sha2-nistp256 AAAATESTECDSA', + '[10.0.0.1]:2222,[centos.ctlplane.localdomain]:2222,[10.0.1.1]:2222,[centos.internalapi.localdomain]:2222,[centos.localdomain]:2222,[instance*]:2222 ssh-rsa AAAATESTRSA', + '[10.0.0.1]:2222,[centos.ctlplane.localdomain]:2222,[10.0.1.1]:2222,[centos.internalapi.localdomain]:2222,[centos.localdomain]:2222,[instance*]:2222 ssh-ed25519 AAAATESTED', + '[10.0.0.1]:2222,[centos.ctlplane.localdomain]:2222,[10.0.1.1]:2222,[centos.internalapi.localdomain]:2222,[centos.localdomain]:2222,[instance*]:2222 ecdsa-sha2-nistp256 AAAATESTECDSA', ] for line in expected: diff --git a/roles/edpm_ssh_known_hosts/tasks/main.yml b/roles/edpm_ssh_known_hosts/tasks/main.yml index f699e21ed..e6124ab76 100644 --- a/roles/edpm_ssh_known_hosts/tasks/main.yml +++ b/roles/edpm_ssh_known_hosts/tasks/main.yml @@ -73,6 +73,13 @@ {% set _ = entries.append(hostdata['canonical_hostname']) %} {% endif %} {% set _ = entries.append(host ~ '*') %} + {% if 'ansible_port' in hostdata and hostdata['ansible_port']|int != 22 %} + {% set hosts = [] %} + {% for host in entries %} + {% set _ = hosts.append("[%s]:%s" % (host, hostdata['ansible_port']) ) %} + {% endfor %} + {% set entries = hosts %} + {% endif %} {% set host = entries|unique|join(',') %} {% for key, type in key_types.items() %} {% if key in hostdata['ansible_facts'] %}