From c582b6584e78922403e296701c0ade252af7a8fe Mon Sep 17 00:00:00 2001 From: yatinkarel Date: Wed, 14 Apr 2021 10:29:42 +0530 Subject: [PATCH] Use ansible_facts in tripleo_ssh_known_hosts role It was missed in original patch to switch to ansible_facts[1]. For providing test value for 'ssh_host_key_rsa_public' overriding it in 'ansible_facts' with set_fact. [1] https://review.opendev.org/c/openstack/tripleo-ansible/+/776666 Closes-Bug: #1923403 Related-Bug: #1915761 Change-Id: I9d5ae576c57eefe5496f9dda71e8eac23e45e89f (cherry picked from commit 30df6f54375bb3ffa0cdd40ca219905b2fa92cf5) --- .../tripleo_ssh_known_hosts/molecule/default/converge.yml | 3 +++ .../tripleo_ssh_known_hosts/molecule/default/molecule.yml | 1 - .../tripleo_ssh_known_hosts/molecule/no_networks/converge.yml | 3 +++ .../tripleo_ssh_known_hosts/molecule/no_networks/molecule.yml | 1 - tripleo_ansible/roles/tripleo_ssh_known_hosts/tasks/main.yml | 4 ++-- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/default/converge.yml b/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/default/converge.yml index 10bfe721f..11d1bf5df 100644 --- a/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/default/converge.yml +++ b/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/default/converge.yml @@ -18,5 +18,8 @@ - name: Converge hosts: all pre_tasks: + - name: Override ssh_host_key_rsa_public test value in ansible_facts + set_fact: + ansible_facts: "{{ ansible_facts|combine({'ssh_host_key_rsa_public': 'AAAATEST'}) }}" roles: - role: "tripleo_ssh_known_hosts" diff --git a/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/default/molecule.yml index a746588bf..5060c7bdb 100644 --- a/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/default/molecule.yml +++ b/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/default/molecule.yml @@ -35,7 +35,6 @@ provisioner: allovercloud: hosts: ubi8: - ansible_ssh_host_key_rsa_public: AAAATEST ctlplane_ip: 10.0.0.1 ctlplane_hostname: ubi8.ctlplane.localdomain internal_api_ip: 10.0.1.1 diff --git a/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/no_networks/converge.yml b/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/no_networks/converge.yml index 10bfe721f..11d1bf5df 100644 --- a/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/no_networks/converge.yml +++ b/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/no_networks/converge.yml @@ -18,5 +18,8 @@ - name: Converge hosts: all pre_tasks: + - name: Override ssh_host_key_rsa_public test value in ansible_facts + set_fact: + ansible_facts: "{{ ansible_facts|combine({'ssh_host_key_rsa_public': 'AAAATEST'}) }}" roles: - role: "tripleo_ssh_known_hosts" diff --git a/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/no_networks/molecule.yml b/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/no_networks/molecule.yml index 32fe63e33..c13b9e5cf 100644 --- a/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/no_networks/molecule.yml +++ b/tripleo_ansible/roles/tripleo_ssh_known_hosts/molecule/no_networks/molecule.yml @@ -35,7 +35,6 @@ provisioner: allovercloud: hosts: ubi8: - ansible_ssh_host_key_rsa_public: AAAATEST log: true env: ANSIBLE_STDOUT_CALLBACK: yaml diff --git a/tripleo_ansible/roles/tripleo_ssh_known_hosts/tasks/main.yml b/tripleo_ansible/roles/tripleo_ssh_known_hosts/tasks/main.yml index 79de25b35..25d3ebed5 100644 --- a/tripleo_ansible/roles/tripleo_ssh_known_hosts/tasks/main.yml +++ b/tripleo_ansible/roles/tripleo_ssh_known_hosts/tasks/main.yml @@ -49,7 +49,7 @@ ssh_known_hosts_lines: |- {% for host in groups['allovercloud'] | intersect(play_hosts) %} {% set hostdata = hostvars[host] %} - {% if 'ansible_ssh_host_key_rsa_public' in hostdata %} + {% if 'ssh_host_key_rsa_public' in hostdata['ansible_facts'] %} {% set entries = [] %} {% set enabled_host_networks = hostdata['tripleo_role_networks']|default([]) %} {% for network in enabled_host_networks %} @@ -64,7 +64,7 @@ {% set _ = entries.append('[' ~ hostdata['canonical_hostname'] ~ ']*') %} {% endif %} {% set _ = entries.append('[' ~ host ~ ']*') %} - {% set line = entries|unique|join(',') ~ ' ssh-rsa ' ~ hostdata['ansible_ssh_host_key_rsa_public'] %} + {% set line = entries|unique|join(',') ~ ' ssh-rsa ' ~ hostdata['ansible_facts']['ssh_host_key_rsa_public'] %} {{ line }} {% endif %} {% endfor %}