Setup passwordless ssh from primary to cluster nodes

Here we add Ansible tasks to the deploy-env role
to setup passwordless ssh from the primary node
to K8s cluster nodes. This is necessary for some
test scripts like for example Ceph migration script.

Change-Id: I1cae1777d51635a19406ea054f4d83972e5fe43c
This commit is contained in:
Vladimir Kozhukalov 2024-06-25 07:05:35 -05:00
parent 1fc147ae50
commit cf4a143e1b
4 changed files with 75 additions and 2 deletions

View File

@ -45,9 +45,8 @@ metallb_setup: false
metallb_pool_cidr: "172.24.128.0/24"
metallb_openstack_endpoint_cidr: "172.24.128.100/24"
client_cluster_ssh_setup: true
client_ssh_user: zuul
client_ssh_key_file: /home/zuul/.ssh/id_rsa
cluster_ssh_user: zuul
openstack_provider_gateway_setup: false

View File

@ -0,0 +1 @@
StrictHostKeyChecking no

View File

@ -0,0 +1,68 @@
# 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: Setup passwordless ssh from primary and cluster nodes
block:
- name: Set client user home directory
set_fact:
client_user_home_directory: /home/{{ client_ssh_user }}
when: client_ssh_user != "root"
- name: Set client user home directory
set_fact:
client_user_home_directory: /root
when: client_ssh_user == "root"
- name: Set cluster user home directory
set_fact:
cluster_user_home_directory: /home/{{ cluster_ssh_user }}
when: cluster_ssh_user != "root"
- name: Set cluster user home directory
set_fact:
cluster_user_home_directory: /root
when: cluster_ssh_user == "root"
- name: Generate ssh key pair
shell: |
ssh-keygen -t ed25519 -q -N "" -f {{ client_user_home_directory }}/.ssh/id_ed25519
args:
creates: "{{ client_user_home_directory }}/.ssh/id_ed25519.pub"
when: (inventory_hostname in (groups['primary'] | default([])))
- name: Read ssh public key
command: cat "{{ client_user_home_directory }}/.ssh/id_ed25519.pub"
register: ssh_public_key
when: (inventory_hostname in (groups['primary'] | default([])))
- name: Set primary wireguard public key
set_fact:
client_ssh_public_key: "{{ (groups['primary'] | map('extract', hostvars, ['ssh_public_key', 'stdout']))[0] }}"
when: inventory_hostname in (groups['k8s_cluster'] | default([]))
- name: Put keys to .ssh/authorized_keys
lineinfile:
path: "{{ cluster_user_home_directory }}/.ssh/authorized_keys"
state: present
line: "{{ client_ssh_public_key }}"
when: inventory_hostname in (groups['k8s_cluster'] | default([]))
- name: Disable strict host key checking
template:
src: "files/ssh_config"
dest: "{{ client_user_home_directory }}/.ssh/config"
owner: "{{ client_ssh_user }}"
mode: 0644
backup: true
when: (inventory_hostname in (groups['primary'] | default([])))
...

View File

@ -80,4 +80,9 @@
include_tasks:
file: client_cluster_tunnel.yaml
when: (groups['primary'] | difference(groups['k8s_control_plane']) | length > 0)
- name: Include client-to-cluster ssh key tasks
include_tasks:
file: client_cluster_ssh.yaml
when: client_cluster_ssh_setup
...