Merge pull request #24 from svc-design/codex/fix-ssh-connection-issue-to-ops-1

Allow customizing SSH user for cluster setup
This commit is contained in:
shenlan 2025-06-26 08:53:13 +08:00 committed by GitHub
commit 3a6d50db3a
5 changed files with 21 additions and 2 deletions

View File

@ -44,6 +44,18 @@ Add the role to your playbook along with the `ssh-trust` role which configures p
- gpu-k8s - gpu-k8s
``` ```
By default the SSH key is created for the same user Ansible connects with. You
can override this by setting `ssh_user`:
```yaml
- hosts: all
vars:
ssh_user: ubuntu
roles:
- ssh-trust
- gpu-k8s
```
Example playbook snippet defining the IP lists: Example playbook snippet defining the IP lists:

View File

@ -9,3 +9,4 @@ master_ips: [] # List of up to three master node IPs
node_ips: [] # List of worker node IPs node_ips: [] # List of worker node IPs
sealos_cmd_env: '{}' sealos_cmd_env: '{}'
kubeadm_init_cmd: "kubeadm init --skip-phases=addon/kube-proxy" kubeadm_init_cmd: "kubeadm init --skip-phases=addon/kube-proxy"
ssh_user: "{{ ansible_user | default('root') }}"

View File

@ -76,7 +76,7 @@
shell: >- shell: >-
ssh -o BatchMode=yes -o StrictHostKeyChecking=no \ ssh -o BatchMode=yes -o StrictHostKeyChecking=no \
-i {{ ansible_ssh_private_key_file | default('~/.ssh/id_rsa') }} \ -i {{ ansible_ssh_private_key_file | default('~/.ssh/id_rsa') }} \
{{ ansible_ssh_user | default(ansible_user, true) | default('root') }}@{{ item }} hostname {{ ssh_user | default(ansible_ssh_user | default(ansible_user, true) | default('root')) }}@{{ item }} hostname
loop: "{{ master_ips + node_ips }}" loop: "{{ master_ips + node_ips }}"
delegate_to: "{{ ops_host | default(masters | default(master_ips) | first) }}" delegate_to: "{{ ops_host | default(masters | default(master_ips) | first) }}"
become: false become: false

View File

@ -0,0 +1,2 @@
# Default user for generating and installing SSH key
ssh_user: "{{ ansible_user | default('root') }}"

View File

@ -5,6 +5,8 @@
executable: /bin/bash executable: /bin/bash
delegate_to: "{{ ops_host }}" delegate_to: "{{ ops_host }}"
run_once: true run_once: true
become: true
become_user: "{{ ssh_user }}"
- name: Fetch ops host public key - name: Fetch ops host public key
slurp: slurp:
@ -12,8 +14,10 @@
register: ops_pub_key register: ops_pub_key
delegate_to: "{{ ops_host }}" delegate_to: "{{ ops_host }}"
run_once: true run_once: true
become: true
become_user: "{{ ssh_user }}"
- name: Authorize ops host key on cluster hosts - name: Authorize ops host key on cluster hosts
ansible.builtin.authorized_key: ansible.builtin.authorized_key:
user: "{{ ansible_user | default('root') }}" user: "{{ ssh_user }}"
key: "{{ ops_pub_key.content | b64decode }}" key: "{{ ops_pub_key.content | b64decode }}"