Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1882248

Summary: FAM theforeman.foreman.repository errors out when no change needed
Product: Red Hat Satellite Reporter: Patrick C. F. Ernzer <pcfe>
Component: Ansible CollectionAssignee: Evgeni Golov <egolov>
Status: CLOSED ERRATA QA Contact: Peter Ondrejka <pondrejk>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.7.0CC: akapse, egolov
Target Milestone: 6.9.0Keywords: Triaged
Target Release: Unused   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: ansible-collection-redhat-satellite-1.5.0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1933167 (view as bug list) Environment:
Last Closed: 2021-04-21 13:17:46 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Patrick C. F. Ernzer 2020-09-24 07:37:40 UTC
Description of problem:
Using a theforeman.foreman.repository task twice errors out on the second run (when no change is needed on that second run)

Version-Release number of selected component (if applicable):
FAM 1.3.0

How reproducible:
always

Steps to Reproduce:
1. run below playbook once
2. make no changes on the Satellite
3. run below paybook again

Actual results:
errors out on second run with 
            "param is missing or the value is empty: repository"

Expected results:
idempotent

Additional info:
File bug upstream at https://github.com/theforeman/foreman-ansible-modules/issues/975

This Bugzilla so that this customer relevant bug is propery tracked. Case will follow momentarily

I get with -vvv

TASK [Ensure Repository for soe-ci generated RHEL 7 RPMs exists] *********************************************************************************************************************************************************
task path: /home/pcfe/work/git/HouseNet/ansible/pcfe.net/satellite-FAM-create-soe-ci-CVs.yml:39
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: pcfe
<127.0.0.1> EXEC /bin/sh -c 'echo ~pcfe && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/pcfe/.ansible/tmp `"&& mkdir "` echo /home/pcfe/.ansible/tmp/ansible-tmp-1600868473.3831494-93673-81858291854066 `" && echo ansible-tmp-1600868473.3831494-93673-81858291854066="` echo /home/pcfe/.ansible/tmp/ansible-tmp-1600868473.3831494-93673-81858291854066 `" ) && sleep 0'
Using module file /home/pcfe/.ansible/collections/ansible_collections/theforeman/foreman/plugins/modules/repository.py
<127.0.0.1> PUT /home/pcfe/.ansible/tmp/ansible-local-93583j0frge0d/tmpx7pa72hn TO /home/pcfe/.ansible/tmp/ansible-tmp-1600868473.3831494-93673-81858291854066/AnsiballZ_repository.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/pcfe/.ansible/tmp/ansible-tmp-1600868473.3831494-93673-81858291854066/ /home/pcfe/.ansible/tmp/ansible-tmp-1600868473.3831494-93673-81858291854066/AnsiballZ_repository.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/pcfe/.ansible/tmp/ansible-tmp-1600868473.3831494-93673-81858291854066/AnsiballZ_repository.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/pcfe/.ansible/tmp/ansible-tmp-1600868473.3831494-93673-81858291854066/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_theforeman.foreman.repository_payload_8m06ix8s/ansible_theforeman.foreman.repository_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 818, in resource_action
    result = self._resource_call(resource, action, resource_payload, options=options, data=data, files=files)
  File "/tmp/ansible_theforeman.foreman.repository_payload_8m06ix8s/ansible_theforeman.foreman.repository_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 446, in _resource_call
    return self._resource(resource).call(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/apypie/resource.py", line 30, in call
    return self.api.call(self.name, action, params, headers, options, data, files)
  File "/usr/lib/python3.8/site-packages/apypie/api.py", line 189, in call
    return self._call_action(action, params, headers, data, files)
  File "/usr/lib/python3.8/site-packages/apypie/api.py", line 194, in _call_action
    return self.http_call(
  File "/usr/lib/python3.8/site-packages/apypie/api.py", line 224, in http_call
    request.raise_for_status()
  File "/usr/lib/python3.8/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
fatal: [localhost]: FAILED! => {
    "changed": false,
    "error": {
        "displayMessage": "Missing values for repository.",
        "errors": [
            "param is missing or the value is empty: repository"
        ]
    },
    "invocation": {
        "module_args": {
            "ansible_collection_requirements": null,
            "auto_enabled": false,
            "checksum_type": "sha256",
            "content_type": "yum",
            "deb_architectures": null,
            "deb_components": null,
            "deb_errata_url": null,
            "deb_releases": null,
            "description": null,
            "docker_tags_whitelist": null,
            "docker_upstream_name": null,
            "download_policy": "immediate",
            "gpg_key": null,
            "http_proxy": null,
            "http_proxy_policy": null,
            "ignorable_content": null,
            "ignore_global_proxy": null,
            "label": "repo-soe-rpms-rhel7",
            "mirror_on_sync": true,
            "name": "repo-soe-rpms-rhel7",
            "organization": "Sat Test",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "product": "prd-ACME-soe",
            "server_url": "https://satellite.internal.pcfe.net",
            "ssl_ca_cert": null,
            "ssl_client_cert": null,
            "ssl_client_key": null,
            "state": "present",
            "unprotected": false,
            "upstream_password": null,
            "upstream_username": null,
            "url": "http://jenkins.internal.pcfe.net/pub/soe-repo/rhel7/",
            "username": "admin",
            "validate_certs": true,
            "verify_ssl_on_sync": false
        }
    },
    "msg": "Error while performing update on repositories: 400 Client Error: Bad Request for url: https://satellite.internal.pcfe.net/katello/api/repositories/3824"
}

and with --check --diff I get

TASK [Ensure Repository for soe-ci generated RHEL 7 RPMs exists] *********************************************************************************************************************************************************
--- before
+++ after
@@ -1,10 +1,10 @@
 {
     "repositories": [
         {
+            "auto_enabled": false,
             "checksum_type": "sha256",
             "content_type": "yum",
             "download_policy": "immediate",
-            "http_proxy_id": null,
             "http_proxy_policy": "global_default_http_proxy",
             "id": 3824,
             "label": "repo-soe-rpms-rhel7",
@@ -12,9 +12,6 @@
             "name": "repo-soe-rpms-rhel7",
             "organization_id": 1,
             "product_id": 320,
-            "ssl_ca_cert_id": null,
-            "ssl_client_cert_id": null,
-            "ssl_client_key_id": null,
             "unprotected": false,
             "url": "http://jenkins.internal.pcfe.net/pub/soe-repo/rhel7/",
             "verify_ssl_on_sync": false

changed: [localhost]


Full playbook;

---
# c.f. https://github.com/theforeman/foreman-ansible-modules
# AND https://theforeman.org/plugins/foreman-ansible-modules/

# my Ansible control node connects to the Satellite server.
# Purely personal preference to run the tasks on another box.
- hosts: localhost

  # put your vars wherever is comforable for you, a Tower, an AWX, a file automatically picked up by Ansible, a file explicitly specified, in this playbook or a mix. Your call, choose what fits your environment best.
  vars_files:
    - "vars/satellite-secrets.yml"

  vars:
    sat_server_url: "https://satellite.internal.pcfe.net"
    sat_username: "admin"
    sat_password: "{{ vaulted_sat6_pass }}"
    sat_org: "Sat Test"
    cu_dept: "ACME"  # Do NOT use spaces, the content of this var is part of labels in Satellite
    repo_url_rpms_rhel7: "http://jenkins.internal.pcfe.net/pub/soe-repo/rhel7/"
    repo_url_rpms_rhel8: "http://jenkins.internal.pcfe.net/pub/soe-repo/rhel8/"
    repo_verify_ssl:     no

  tasks:
    - name: "Ensure Product used by soe-ci exists and is current in Satellite"
      theforeman.foreman.product:
        username:     "{{ sat_username }}"
        password:     "{{ vaulted_sat6_pass }}"
        server_url:   "{{ sat_server_url }}"
        organization: "{{ sat_org }}"
        name:         "prd-{{ cu_dept }}-soe"
        description:  "Used by soe-ci, managed by Ansible. Do not automatically sync, soe-ci handles syncing."
        state:        present

    - name: "Ensure Repository for soe-ci generated RHEL 7 RPMs exists"
      theforeman.foreman.repository:
        username:     "{{ sat_username }}"
        password:     "{{ vaulted_sat6_pass }}"
        server_url:   "{{ sat_server_url }}"
        organization: "{{ sat_org }}"
        auto_enabled:       no
        checksum_type:      sha256
        content_type:       yum
        download_policy:    immediate
        mirror_on_sync:     yes
        label:              repo-soe-rpms-rhel7
        name:               repo-soe-rpms-rhel7
        product:            "prd-{{ cu_dept }}-soe"
        state:              present
        unprotected:        no
        url:                "{{ repo_url_rpms_rhel7 }}"
        verify_ssl_on_sync: "{{ repo_verify_ssl }}"

    - name: "Ensure Repository for soe-ci generated RHEL 8 RPMs exists"
      theforeman.foreman.repository:
        username:     "{{ sat_username }}"
        password:     "{{ vaulted_sat6_pass }}"
        server_url:   "{{ sat_server_url }}"
        organization: "{{ sat_org }}"
        auto_enabled:     no
        checksum_type:    sha256
        content_type:     yum
        download_policy:  immediate
        mirror_on_sync:   yes
        label:            repo-soe-rpms-rhel8
        name:             repo-soe-rpms-rhel8
        product:          "prd-{{ cu_dept }}-soe"
        state:            present
        unprotected:      no
        url:              "{{ repo_url_rpms_rhel8 }}"
        verify_ssl_on_sync: "{{ repo_verify_ssl }}"

Comment 1 Brad Buckingham 2021-01-08 21:57:18 UTC
An early Satellite 6.9 SNAP includes ansible-collection-redhat-satellite-1.5.1-1.el7sat.noarch.rpm; therefore, aligning this to the release and updating state.

Comment 2 Peter Ondrejka 2021-03-10 10:36:57 UTC
Verified on Satellite 6.9 sn 16 using similar playbook as in problem description, "missing values" error no longer occurs, the second run passes with:

PLAY RECAP *******************************************************************************************************************
hostname : ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Comment 5 errata-xmlrpc 2021-04-21 13:17:46 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.9 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:1313