From 912de5adf2ca5ed8951898ce4e57287ac658ca82 Mon Sep 17 00:00:00 2001 From: John Fulton Date: Thu, 16 Jan 2025 15:50:50 -0500 Subject: [PATCH 1/2] Handle adoption when radosgw_address_block is comma delimited list In cephadm-adopt.yml TASK "Update the placement of radosgw hosts" passes module ceph_orch_apply embedded YAML via a block scalar. This YAML creates a Ceph spec of service_type RGW. The networks key of this spec supports either a list or a string. Without this patch, the networks key of the spec will only contain a string. With this patch a string is still set for the networks key, but if Ansible var radosgw_address_block contains commas, then var radosgw_address_block is split by those commas into a list and the networks key of the spec will be set to a list. Closes: https://issues.redhat.com/browse/RHCEPH-10418 Signed-off-by: John Fulton --- infrastructure-playbooks/cephadm-adopt.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure-playbooks/cephadm-adopt.yml b/infrastructure-playbooks/cephadm-adopt.yml index e542dcdd7c..612e5fe864 100644 --- a/infrastructure-playbooks/cephadm-adopt.yml +++ b/infrastructure-playbooks/cephadm-adopt.yml @@ -950,7 +950,7 @@ hosts: - {{ ansible_facts['nodename'] }} {% if rgw_subnet is defined %} - networks: "{{ radosgw_address_block }}" + networks: {{ radosgw_address_block.split(',') | list if ',' in radosgw_address_block else radosgw_address_block | string }} {% endif %} spec: rgw_frontend_port: {{ radosgw_frontend_port }} From f521b64b575710b6202cf134c6fea472b81f7a90 Mon Sep 17 00:00:00 2001 From: John Fulton Date: Thu, 16 Jan 2025 16:30:20 -0500 Subject: [PATCH 2/2] Handle radosgw hosts placement with non-default cluster name In cephadm-adopt.yml TASK "Update the placement of radosgw hosts" does not handle when Ansible var cluster is something other than "ceph", unless this patch is used. Update module ceph_orch_apply to support optional cluster parameter using the same style as in module ceph_config. The command is only extended to inclue the new keyring and config options if cluster name is not ceph. This patch is necessary to migrate older clusters which were deployed when custom names were supported. Closes: https://issues.redhat.com/browse/RHCEPH-10442 Signed-off-by: John Fulton --- infrastructure-playbooks/cephadm-adopt.yml | 3 +++ library/ceph_orch_apply.py | 30 +++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/infrastructure-playbooks/cephadm-adopt.yml b/infrastructure-playbooks/cephadm-adopt.yml index 612e5fe864..421d86eb72 100644 --- a/infrastructure-playbooks/cephadm-adopt.yml +++ b/infrastructure-playbooks/cephadm-adopt.yml @@ -942,6 +942,7 @@ - name: Update the placement of radosgw hosts ceph_orch_apply: fsid: "{{ fsid }}" + cluster: "{{ cluster }}" spec: | service_type: rgw service_id: {{ ansible_facts['hostname'] }} @@ -1480,6 +1481,7 @@ - name: Update the placement of alertmanager hosts ceph_orch_apply: fsid: "{{ fsid }}" + cluster: "{{ cluster }}" spec: | service_type: alertmanager service_id: "{{ ansible_facts['hostname'] }}" @@ -1503,6 +1505,7 @@ - name: Update the placement of prometheus hosts ceph_orch_apply: fsid: "{{ fsid }}" + cluster: "{{ cluster }}" spec: | service_name: prometheus service_id: "{{ ansible_facts['hostname'] }}" diff --git a/library/ceph_orch_apply.py b/library/ceph_orch_apply.py index 1df457b09f..d5b1b32c94 100644 --- a/library/ceph_orch_apply.py +++ b/library/ceph_orch_apply.py @@ -23,9 +23,9 @@ from ansible.module_utils.basic import AnsibleModule # type: ignore try: - from ansible.module_utils.ca_common import exit_module, build_base_cmd_orch # type: ignore + from ansible.module_utils.ca_common import exit_module, build_base_cmd # type: ignore except ImportError: - from module_utils.ca_common import exit_module, build_base_cmd_orch + from module_utils.ca_common import exit_module, build_base_cmd ANSIBLE_METADATA = { @@ -50,6 +50,10 @@ description: - The Ceph container image to use. required: false + cluster: + description: + - The Ceph cluster name. Defaults to ceph + required: false spec: description: - The service spec to apply @@ -81,8 +85,13 @@ def parse_spec(spec: str) -> Dict: def retrieve_current_spec(module: AnsibleModule, expected_spec: Dict) -> Dict: """ retrieve current config of the service """ service: str = expected_spec["service_type"] - cmd = build_base_cmd_orch(module) - cmd.extend(['ls', service]) + cmd = build_base_cmd(module) + cluster = module.params.get('cluster') + if cluster != 'ceph': + conf_path = f"/etc/ceph/{cluster}.conf" + keyring_path = f"/etc/ceph/{cluster}.client.admin.keyring" + cmd.extend(['--config', conf_path, '--keyring', keyring_path]) + cmd.extend(['ceph', 'orch', 'ls', service]) if 'service_name' in expected_spec: cmd.extend([expected_spec["service_name"]]) else: @@ -98,8 +107,13 @@ def retrieve_current_spec(module: AnsibleModule, expected_spec: Dict) -> Dict: def apply_spec(module: "AnsibleModule", data: str) -> Tuple[int, List[str], str, str]: - cmd = build_base_cmd_orch(module) - cmd.extend(['apply', '-i', '-']) + cmd = build_base_cmd(module) + cluster = module.params.get('cluster') + if cluster != 'ceph': + conf_path = f"/etc/ceph/{cluster}.conf" + keyring_path = f"/etc/ceph/{cluster}.client.admin.keyring" + cmd.extend(['--config', conf_path, '--keyring', keyring_path]) + cmd.extend(['ceph', 'orch', 'apply', '-i', '-']) rc, out, err = module.run_command(cmd, data=data) if rc: @@ -131,7 +145,9 @@ def run_module() -> None: docker=dict(type=bool, required=False, default=False), - image=dict(type='str', required=False) + image=dict(type='str', required=False), + cluster=dict(type='str', required=False, + default='ceph') ) module = AnsibleModule(