Skip to content

Commit 11677d6

Browse files
asm0deuzguits
authored andcommitted
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) (cherry picked from commit c3ce6fc)
1 parent 445acc9 commit 11677d6

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
@@ -249,26 +249,64 @@
249249
run_once: true
250250
delegate_to: '{{ groups[mon_group_name][0] }}'
251251

252-
- name: generate cephadm ssh key
252+
- name: check if there is an existing ssh keypair
253+
stat:
254+
path: "{{ item }}"
255+
loop:
256+
- "{{ cephadm_ssh_priv_key_path }}"
257+
- "{{ cephadm_ssh_pub_key_path }}"
258+
register: ssh_keys
259+
changed_when: false
260+
run_once: true
261+
delegate_to: '{{ groups[mon_group_name][0] }}'
262+
263+
- name: set fact
264+
set_fact:
265+
stat_ssh_key_pair: "{{ ssh_keys.results | map(attribute='stat.exists') | list }}"
266+
267+
- name: fail if either ssh public or private key is missing
268+
fail:
269+
msg: "One part of the ssh keypair of user {{ cephadm_ssh_user }} is missing"
270+
when:
271+
- false in stat_ssh_key_pair
272+
- true in stat_ssh_key_pair
273+
274+
- name: generate cephadm ssh key if there is none
253275
command: "{{ ceph_cmd }} cephadm generate-key"
276+
when: not true in stat_ssh_key_pair
254277
changed_when: false
255278
run_once: true
256279
delegate_to: '{{ groups[mon_group_name][0] }}'
257280

281+
- name: use existing user keypair for remote connections
282+
when: not false in stat_ssh_key_pair
283+
delegate_to: "{{ groups[mon_group_name][0] }}"
284+
run_once: true
285+
command: >
286+
{{ container_binary + ' run --rm --net=host --security-opt label=disable
287+
-v /etc/ceph:/etc/ceph:z
288+
-v /var/lib/ceph:/var/lib/ceph:ro
289+
-v /var/run/ceph:/var/run/ceph:z
290+
-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' }}
291+
--cluster {{ cluster }} config-key set mgr/cephadm/ssh_identity_{{ item.0 }} -i /etc/ceph/cephadm.{{ item.0 }}
292+
with_together:
293+
- [ 'pub', 'key' ]
294+
- [ '{{ cephadm_ssh_pub_key_path }}', '{{ cephadm_ssh_priv_key_path }}' ]
295+
258296
- name: get the cephadm ssh pub key
259297
command: "{{ ceph_cmd }} cephadm get-pub-key"
260298
changed_when: false
261299
run_once: true
262300
register: cephadm_pubpkey
263301
delegate_to: '{{ groups[mon_group_name][0] }}'
264302

265-
- name: allow cephadm key for {{ cephadm_ssh_user | default('root') }} account
303+
- name: allow cephadm key for {{ cephadm_ssh_user }} account
266304
authorized_key:
267-
user: "{{ cephadm_ssh_user | default('root') }}"
305+
user: "{{ cephadm_ssh_user }}"
268306
key: '{{ cephadm_pubpkey.stdout }}'
269307

270-
- name: set cephadm ssh user to {{ cephadm_ssh_user | default('root') }}
271-
command: "{{ ceph_cmd }} cephadm set-user {{ cephadm_ssh_user | default('root') }}"
308+
- name: set cephadm ssh user to {{ cephadm_ssh_user }}
309+
command: "{{ ceph_cmd }} cephadm set-user {{ cephadm_ssh_user }}"
272310
changed_when: false
273311
run_once: true
274312
delegate_to: "{{ groups[mon_group_name][0] }}"
@@ -323,13 +361,13 @@
323361
when: is_hci | bool
324362

325363
- name: manage nodes with cephadm - ipv4
326-
command: "{{ ceph_cmd }} orch host add {{ ansible_facts['nodename'] }} {{ ansible_facts['all_ipv4_addresses'] | ips_in_ranges(public_network.split(',')) | first }} {{ group_names | join(' ') }}"
364+
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(' ') }}"
327365
changed_when: false
328366
delegate_to: '{{ groups[mon_group_name][0] }}'
329367
when: ip_version == 'ipv4'
330368

331369
- name: manage nodes with cephadm - ipv6
332-
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(' ') }}"
370+
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(' ') }}"
333371
changed_when: false
334372
delegate_to: '{{ groups[mon_group_name][0] }}'
335373
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)