@@ -120,9 +120,19 @@ def parse_spec(spec: str) -> Dict:
120120def 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