Fix running remote play on random ssh port

This fixes the ability to run the backup play (or any play for that
matter) remotely when ansible_port is configured on /etc/ansible/hosts

TEST PLAN
PASS Remote play of the backup playbook
PASS Local play of the backup playbook
PASS Remote play of the restore playbook
PASS Local play of the restore playbook

Closes-Bug: #1986554
Signed-off-by: Thiago Brito <thiago.brito@windriver.com>
Change-Id: I48227d2e00b16aaa595aec6d628ce36ea1c8ba51
This commit is contained in:
Thiago Brito 2022-08-15 15:01:12 -03:00
parent b64268811d
commit e251470059
2 changed files with 2 additions and 11 deletions

View File

@ -38,15 +38,6 @@
ansible_host: "{{ ansible_host | ipaddr }}"
when: ansible_host | ipaddr
- name: Set SSH hostname
set_fact:
ssh_hostname: "{{ ansible_host }}"
- name: Set SSH hostname if SSH port is not default
set_fact:
ssh_hostname: "[{{ ansible_host }}]:{{ ansible_port }}"
when: ansible_port != '22'
- name: Check connectivity
local_action: command ping -c 1 {{ ansible_host }}
failed_when: false
@ -59,7 +50,7 @@
when: ping_result.rc != 0 and item is search('100% packet loss')
- name: Gather remote SSH public key
command: ssh-keyscan -T 20 -t ecdsa {{ ssh_hostname }}
command: "ssh-keyscan -T 20 -t ecdsa -p {{ ansible_port if ansible_port else 22 }} {{ ansible_host }}"
register: remote_keyscan
until: remote_keyscan.stdout != ""
retries: 6

View File

@ -162,7 +162,7 @@
- block:
- name: Gather latest SSH public key
command: ssh-keyscan -T 20 -t ecdsa {{ ssh_hostname }}
command: ssh-keyscan -T 20 -t ecdsa -p {{ ansible_port if ansible_port else 22 }} {{ ansible_host }}
register: remote_keyscan
until: remote_keyscan.stdout != ""
retries: 6