This repository was archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathssh_keyscan.yml
57 lines (51 loc) · 1.92 KB
/
ssh_keyscan.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
# Copyright 2018 IBM Corp.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Generate known_hosts file with client host keys
hosts: localhost
tasks:
- name: Include localhost variables
include_vars: host_vars/localhost
- name: Get list of client IP addresses
command: "{{ python_executable_local }} \
{{ scripts_path_local }}/python/client_ip_list.py --deployer"
register: client_ips
- name: Use ssh-keyscan to add each client hostkey to known_hosts file
shell: "ssh-keyscan -H {{ item }} >> {{ known_hosts }}"
with_items: "{{ client_ips.stdout.split(',') }}"
- name: Register generated known_hosts content
command: "cat {{ known_hosts }}"
register: known_hosts_content
- name: Append generated known_hosts contect to ~/.ssh/known_hosts
lineinfile:
line: "{{ item }}"
dest: ~/.ssh/known_hosts
state: present
create: "yes"
mode: 0600
with_items: "{{ known_hosts_content.stdout_lines }}"
- name: Copy known_hosts entries to deployer and client nodes
hosts: deployer:client_nodes
gather_facts: True
tasks:
- name: Append generated known_hosts contect to ~/.ssh/known_hosts
lineinfile:
line: "{{ item }}"
dest: ~/.ssh/known_hosts
state: present
create: "yes"
mode: 0600
with_items: "{{ hostvars['localhost']['known_hosts_content'].stdout_lines }}"