kayobe/ansible/roles/ssh-known-host/tasks/main.yml
Pierre Riteau c5b2d435ee Fix concurrency issues while adding SSH keys to known_hosts
Co-Authored-By: Mark Goddard <mark@stackhpc.com>

Change-Id: Ie0b98e7364c1c00dc017129e86843962f924247b
Story: 2007628
Task: 39672
2020-05-11 15:44:18 +02:00

36 lines
1.5 KiB
YAML

---
# If no IP address has been configured for the host on the admin network, this
# is typically the first task to fail. Provide a friendly message with
# information on how to resolve the issue.
- name: Validate SSH address
fail:
msg: >-
Host {{ inventory_hostname }} has no address configured on the admin
network. IP addresses may be manually configured in
'network-allocations.yml', or are automatically allocated during the
following commands: 'kayobe seed hypervisor host configure', 'kayobe
seed host configure', 'kayobe overcloud host configure', 'kayobe seed
vm provision' and 'kayobe overcloud inventory discover'.
when: not ansible_host | default(inventory_hostname)
- name: Scan for SSH keys
local_action:
module: command ssh-keyscan {{ item }}
with_items:
- "{{ ansible_host|default(inventory_hostname) }}"
register: keyscan_result
changed_when: False
# NOTE(priteau): Run this task serially as known_hosts is not safe to execute
# concurrently, and some keys can end up being dropped. For more details see
# https://github.com/ansible/proposals/issues/113
- name: Ensure SSH keys are in known hosts
local_action:
module: known_hosts
host: "{{ item[0].item }}"
key: "{{ item[1] }}"
# TODO(priteau): Replace the following with "throttle: 1" once we require
# Ansible >= 2.9
loop: "{{ query('subelements', ansible_play_batch | map('extract', hostvars, ['keyscan_result', 'results']) | map('first') | list, 'stdout_lines') }}"
run_once: True