Skip to content

Commit ad25a6f

Browse files
castorskyasm0deuz
authored andcommitted
fix: idempotency check for services without 'service_id'
Fixed idempotency check for services that do not require the 'service_id' key in the specification and the 'host' service type. Signed-off-by: Castor Sky <csky57@gmail.com>
1 parent 23d2ffe commit ad25a6f

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bugfixes:
2+
- >
3+
ceph_orch_apply - Fixed idempotency check for services that do not require the 'service_id' key in the specification
4+
and the 'host' service type (https://github.com/ceph/ceph.automation/pull/12).

plugins/modules/ceph_orch_apply.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,19 @@ def parse_spec(spec: str) -> Dict:
120120
def retrieve_current_spec(module: AnsibleModule, expected_spec: Dict) -> Dict:
121121
""" retrieve current config of the service """
122122
service: str = expected_spec["service_type"]
123-
srv_name: str = "%s.%s" % (expected_spec["service_type"], expected_spec["service_id"])
123+
# Key "service_id" is mandatory only for exact subset of services.
124+
# https://docs.ceph.com/en/latest/cephadm/services/#ceph.deployment.service_spec.ServiceSpec.service_id
125+
if service in ["iscsi", "nvmeof", "mds", "nfs", "osd", "rgw", "container", "ingress"]:
126+
srv_name: str = "%s.%s" % (service, expected_spec["service_id"])
127+
else:
128+
srv_name: str = service
124129
cmd = build_base_cmd_orch(module)
125-
cmd.extend(['ls', service, srv_name, '--format=yaml'])
130+
# Hosts are not services but can be deployed with `ceph orch apply` like regular services.
131+
# And `ceph orch` has different syntax to list hosts.
132+
if service != "host":
133+
cmd.extend(['ls', service, srv_name, '--format=yaml'])
134+
else:
135+
cmd.extend(['host', 'ls', '--host-pattern', expected_spec['hostname'], '--format=yaml'])
126136
out = module.run_command(cmd)
127137
if isinstance(out, str):
128138
# if there is no existing service, cephadm returns the string 'No services reported'
@@ -148,13 +158,20 @@ def change_required(current: Dict, expected: Dict) -> bool:
148158
if not current:
149159
return True
150160

161+
# Listing of hosts never returns 'service_type', but expected spec has it.
162+
if expected['service_type'] == 'host':
163+
current['service_type'] = 'host'
164+
151165
for key, value in expected.items():
152166
if key in current:
153167
if current[key] != value:
154168
return True
155169
continue
156170
else:
157-
return True
171+
# "Location" key in the host spec is a one-time use key - it is not stored in the database.
172+
# This key should not appear in the "current" spec, and it is safe to skip this key.
173+
if key != 'location':
174+
return True
158175
return False
159176

160177

0 commit comments

Comments
 (0)