Bug 1967904 - Updating a hostgroup using redhat.satellite.hostgroup collection removing the existing parameters and activation key details.
Summary: Updating a hostgroup using redhat.satellite.hostgroup collection removing the...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Ansible Collection
Version: 6.9.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: 6.10.0
Assignee: Evgeni Golov
QA Contact: Vladimír Sedmík
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-06-04 10:57 UTC by Gourav Padholia
Modified: 2021-12-14 07:56 UTC (History)
5 users (show)

Fixed In Version: ansible-collection-redhat-satellite-2.1.1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-11-16 14:11:38 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github theforeman foreman-ansible-modules issues 1268 0 None None None 2021-08-25 17:04:16 UTC
Github theforeman foreman-ansible-modules pull 1240 0 None closed don't override already set parameters when passing an activation key 2021-07-22 18:30:47 UTC
Red Hat Product Errata RHSA-2021:4702 0 None None None 2021-11-16 14:12:00 UTC

Description Gourav Padholia 2021-06-04 10:57:58 UTC
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.

Comment 2 Evgeni Golov 2021-06-04 11:43:42 UTC
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?

Comment 5 Matt 2021-07-23 18:29:07 UTC
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?

Comment 6 Evgeni Golov 2021-07-23 19:09:59 UTC
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

Comment 7 Matt 2021-07-23 19:18:23 UTC
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"}]

Comment 8 Evgeni Golov 2021-07-23 19:29:27 UTC
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")

Comment 9 Evgeni Golov 2021-07-23 19:31:05 UTC
oooh, but I think I see a logic bug in that deduplication code. damn!

Comment 10 Evgeni Golov 2021-07-23 19:42:26 UTC
I've filed https://github.com/theforeman/foreman-ansible-modules/issues/1268 as a follow up issue

Comment 11 Matt 2021-07-23 19:53:32 UTC
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.

Comment 12 Vladimír Sedmík 2021-08-25 17:17:45 UTC
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

Comment 15 errata-xmlrpc 2021-11-16 14:11:38 UTC
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


Note You need to log in before you can comment on or make changes to this bug.