Skip to content

Commit 10a5e54

Browse files
asm0deuzguits
authored andcommittedMar 4, 2022
Enable user to change the account used for ssh connection
By default cephadm uses root account to connect remotely to other nodes in the cluster. This change allows to choose another account. This commit also allows to use a dedicated subnet for cephadm mgmt. Signed-off-by: Teoman ONAY <tonay@redhat.com> (cherry picked from commit da42f3d)
1 parent d787836 commit 10a5e54

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed
 

‎group_vars/all.yml.sample

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ dummy:
7474
#ceph_dashboard_firewall_zone: public
7575
#ceph_rgwloadbalancer_firewall_zone: public
7676

77+
# cephadm account for remote connections
78+
#cephadm_ssh_user: root
79+
#cephadm_ssh_priv_key_path: "/home/{{ cephadm_ssh_user }}/.ssh/id_rsa"
80+
#cephadm_ssh_pub_key_path: "{{ cephadm_ssh_priv_key_path }}.pub"
81+
#cephadm_mgmt_network: "{{ public_network }}"
7782

7883
############
7984
# PACKAGES #

‎group_vars/rhcs.yml.sample

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ dummy:
7474
#ceph_dashboard_firewall_zone: public
7575
#ceph_rgwloadbalancer_firewall_zone: public
7676

77+
# cephadm account for remote connections
78+
#cephadm_ssh_user: root
79+
#cephadm_ssh_priv_key_path: "/home/{{ cephadm_ssh_user }}/.ssh/id_rsa"
80+
#cephadm_ssh_pub_key_path: "{{ cephadm_ssh_priv_key_path }}.pub"
81+
#cephadm_mgmt_network: "{{ public_network }}"
7782

7883
############
7984
# PACKAGES #

‎infrastructure-playbooks/cephadm-adopt.yml

+45-7
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,64 @@
213213
run_once: true
214214
delegate_to: '{{ groups[mon_group_name][0] }}'
215215

216-
- name: generate cephadm ssh key
216+
- name: check if there is an existing ssh keypair
217+
stat:
218+
path: "{{ item }}"
219+
loop:
220+
- "{{ cephadm_ssh_priv_key_path }}"
221+
- "{{ cephadm_ssh_pub_key_path }}"
222+
register: ssh_keys
223+
changed_when: false
224+
run_once: true
225+
delegate_to: '{{ groups[mon_group_name][0] }}'
226+
227+
- name: set fact
228+
set_fact:
229+
stat_ssh_key_pair: "{{ ssh_keys.results | map(attribute='stat.exists') | list }}"
230+
231+
- name: fail if either ssh public or private key is missing
232+
fail:
233+
msg: "One part of the ssh keypair of user {{ cephadm_ssh_user }} is missing"
234+
when:
235+
- false in stat_ssh_key_pair
236+
- true in stat_ssh_key_pair
237+
238+
- name: generate cephadm ssh key if there is none
217239
command: "{{ ceph_cmd }} cephadm generate-key"
240+
when: not true in stat_ssh_key_pair
218241
changed_when: false
219242
run_once: true
220243
delegate_to: '{{ groups[mon_group_name][0] }}'
221244

245+
- name: use existing user keypair for remote connections
246+
when: not false in stat_ssh_key_pair
247+
delegate_to: "{{ groups[mon_group_name][0] }}"
248+
run_once: true
249+
command: >
250+
{{ container_binary + ' run --rm --net=host --security-opt label=disable
251+
-v /etc/ceph:/etc/ceph:z
252+
-v /var/lib/ceph:/var/lib/ceph:ro
253+
-v /var/run/ceph:/var/run/ceph:z
254+
-v ' + item.1 + ':/etc/ceph/cephadm.' + item.0 + ':ro --entrypoint=ceph '+ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else 'ceph' }}
255+
--cluster {{ cluster }} config-key set mgr/cephadm/ssh_identity_{{ item.0 }} -i /etc/ceph/cephadm.{{ item.0 }}
256+
with_together:
257+
- [ 'pub', 'key' ]
258+
- [ '{{ cephadm_ssh_pub_key_path }}', '{{ cephadm_ssh_priv_key_path }}' ]
259+
222260
- name: get the cephadm ssh pub key
223261
command: "{{ ceph_cmd }} cephadm get-pub-key"
224262
changed_when: false
225263
run_once: true
226264
register: cephadm_pubpkey
227265
delegate_to: '{{ groups[mon_group_name][0] }}'
228266

229-
- name: allow cephadm key for {{ cephadm_ssh_user | default('root') }} account
267+
- name: allow cephadm key for {{ cephadm_ssh_user }} account
230268
authorized_key:
231-
user: "{{ cephadm_ssh_user | default('root') }}"
269+
user: "{{ cephadm_ssh_user }}"
232270
key: '{{ cephadm_pubpkey.stdout }}'
233271

234-
- name: set cephadm ssh user to {{ cephadm_ssh_user | default('root') }}
235-
command: "{{ ceph_cmd }} cephadm set-user {{ cephadm_ssh_user | default('root') }}"
272+
- name: set cephadm ssh user to {{ cephadm_ssh_user }}
273+
command: "{{ ceph_cmd }} cephadm set-user {{ cephadm_ssh_user }}"
236274
changed_when: false
237275
run_once: true
238276
delegate_to: "{{ groups[mon_group_name][0] }}"
@@ -287,13 +325,13 @@
287325
when: is_hci | bool
288326

289327
- name: manage nodes with cephadm - ipv4
290-
command: "{{ ceph_cmd }} orch host add {{ ansible_facts['nodename'] }} {{ ansible_facts['all_ipv4_addresses'] | ips_in_ranges(public_network.split(',')) | first }} {{ group_names | join(' ') }}"
328+
command: "{{ ceph_cmd }} orch host add {{ ansible_facts['nodename'] }} {{ ansible_facts['all_ipv4_addresses'] | ips_in_ranges(cephadm_mgmt_network.split(',')) | first }} {{ group_names | join(' ') }}"
291329
changed_when: false
292330
delegate_to: '{{ groups[mon_group_name][0] }}'
293331
when: ip_version == 'ipv4'
294332

295333
- name: manage nodes with cephadm - ipv6
296-
command: "{{ ceph_cmd }} orch host add {{ ansible_facts['nodename'] }} {{ ansible_facts['all_ipv6_addresses'] | ips_in_ranges(public_network.split(',')) | last | ipwrap }} {{ group_names | join(' ') }}"
334+
command: "{{ ceph_cmd }} orch host add {{ ansible_facts['nodename'] }} {{ ansible_facts['all_ipv6_addresses'] | ips_in_ranges(cephadm_mgmt_network.split(',')) | last | ipwrap }} {{ group_names | join(' ') }}"
297335
changed_when: false
298336
delegate_to: '{{ groups[mon_group_name][0] }}'
299337
when: ip_version == 'ipv6'

‎roles/ceph-defaults/defaults/main.yml

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ ceph_iscsi_firewall_zone: public
6666
ceph_dashboard_firewall_zone: public
6767
ceph_rgwloadbalancer_firewall_zone: public
6868

69+
# cephadm account for remote connections
70+
cephadm_ssh_user: root
71+
cephadm_ssh_priv_key_path: "/home/{{ cephadm_ssh_user }}/.ssh/id_rsa"
72+
cephadm_ssh_pub_key_path: "{{ cephadm_ssh_priv_key_path }}.pub"
73+
cephadm_mgmt_network: "{{ public_network }}"
6974

7075
############
7176
# PACKAGES #

0 commit comments

Comments
 (0)