Description of problem: Updating a host group using the ansible collection redhat.satellite.hostgroup will remove the existing parameters and activation keys if these details not provided in the playbook. Version-Release number of selected component (if applicable): 6.8 and 6.9 How reproducible: 100 % Steps to Reproduce: 1. Create a host group and provide the parameters and activation key, and save the host group. 2. Update the host group using the ansible collection redhat.satellite.hostgroup. While writing a playbook does not provide activation_keys and parameters. 3. Run the playbook, this will show 2 changes and remove the existing activation keys and parameters. Actual results: Activation key and parameters deleted. Expected results: This should not be deleted, there is a high chance of data loss if the playbook runs without these parameters. Additional info: Other parameters like content view, lifecycle environment, architecture and compute profile not deleted if the playbook runs without these parameters.
This shouldn't happen when you don't provide *neither* AK not params, but I can see how this can happen if you provide ONLY one of them (due to the way how AK internally is just a magic param). The later is definitely a bug. Can you confirm the former is not what you're describing?
When using version 2.1.1 of the redhat.satellite collection using ansible 2.9.18 and python 3.6.8, something we previously had working broke, I believe because of this fix. I'm not sure if our expected behavior was incorrect. Say we had host group A with Activation key "RHEL 7" already created. If we then call the redhat.satellite.hostgroup module with the same host group name and the same "RHEL 7" AK, we get the following error: fatal: [hostname]: FAILED! => {"changed": false, "failed_when_result": true, "msg": "There are duplicate keys in 'parameters': ['kt_activation_keys'}."} Please note we are operating in an enclave and I had to freetype that error so excuse any fat fingering on my end. It looks as though the AK is being retained from the original creation and the new AK (which happens to be exactly the same) is being appended, without removing any duplicates first and then validate_parameters may be outputting the duplicate_keys parameter. My expectation is that the module would remove any duplicates between the original and new insert and not require it to be an append only. Iss this expectation correct and if so, is this a bug with the fixed code as a result?
Hey Matt, so I am reading your description as you have the following playbook: - name: create HG with AK redhat.satellite.hostgroup: name: test activation_keys: testkey and run it twice, the second run results in "duplicate keys" error? that certainly shouldn't be the case. we *do* have tests for that (https://github.com/theforeman/foreman-ansible-modules/blob/604f60b884707ee25282155c1fe5b5f0146a943d/tests/test_playbooks/katello_hostgroup.yml#L43-L100), so I wonder if there is something else in the playbook that might be doing this? btw, the code that does the deduplication is here: https://github.com/theforeman/foreman-ansible-modules/blob/604f60b884707ee25282155c1fe5b5f0146a943d/plugins/module_utils/foreman_helper.py#L320-L330
Maybe we are doing it wrong but we have: - name: Sample Name redhat.satellite/hostgroup: name: test parameters: [{name: kt_activation_keys, value: "RHEL 7"}]
besides rather unusual (albeit valid) formatting, I see nothing wrong with that. out of curiosity, does the behavior change, if you use my syntax, with the explicit "activation_keys" syntax? (which is just an alias to add it to "parameters")
oooh, but I think I see a logic bug in that deduplication code. damn!
I've filed https://github.com/theforeman/foreman-ansible-modules/issues/1268 as a follow up issue
FWIW, we just tried it your way with activation_keys and that seems to work. Its also much cleaner than what we were doing so we will change to that. Appreciate the thorough review though.
Verified on Sat 6.10.0 snap 14 with ansible-collection-redhat-satellite-2.1.2-1.el7sat.noarch Steps: 1) Created a hostgroup with some AK and Parameters Using redhat.satellite.hostgroup: 2) Updated the HG with new Activation Keys only -> Parameters were left untouched 3) Updated the HG with new Parameters only -> Activation Keys were left untouched 4) Updated the HG with both -> both were updated successfully 5) Updated the HG without providing any Activation Keys nor Parameters -> both were left untouched 6) Playbook reruns end with ok 7) Using the syntax from Comment#7 will succeed only if no AK existed in the HG before, so here the playbook rerun will fail. This was already fixed in 2.2.0 and will be tracked by BZ#1997724
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (Moderate: Satellite 6.10 Release), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2021:4702