diff --git a/changelogs/fragments/1268-ak_param_duplicate.yml b/changelogs/fragments/1268-ak_param_duplicate.yml new file mode 100644 index 0000000000..951d1f15a5 --- /dev/null +++ b/changelogs/fragments/1268-ak_param_duplicate.yml @@ -0,0 +1,2 @@ +bugfixes: + - host, hostgroup - don't accidentally duplicate ``kt_activation_keys`` param (https://github.com/theforeman/foreman-ansible-modules/issues/1268) diff --git a/plugins/module_utils/foreman_helper.py b/plugins/module_utils/foreman_helper.py index 5a4007330d..69fe11977a 100644 --- a/plugins/module_utils/foreman_helper.py +++ b/plugins/module_utils/foreman_helper.py @@ -325,9 +325,10 @@ def run(self, **kwargs): ak_param = {'name': 'kt_activation_keys', 'parameter_type': 'string', 'value': self.foreman_params.pop('activation_keys')} self.foreman_params['parameters'] = parameters + [ak_param] elif 'parameters' in self.foreman_params and entity is not None: - ak_param = next((param for param in entity.get('parameters') if param['name'] == 'kt_activation_keys'), None) - if ak_param: - self.foreman_params['parameters'].append(ak_param) + current_ak_param = next((param for param in entity.get('parameters') if param['name'] == 'kt_activation_keys'), None) + desired_ak_param = next((param for param in self.foreman_params['parameters'] if param['name'] == 'kt_activation_keys'), None) + if current_ak_param and desired_ak_param is None: + self.foreman_params['parameters'].append(current_ak_param) self.validate_parameters()