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 1878693 - Unable to perform image based deployment using hosts module from Red Hat Satellite Ansible Collections
Summary: Unable to perform image based deployment using hosts module from Red Hat Sate...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Ansible Collection
Version: 6.7.0
Hardware: All
OS: Unspecified
unspecified
high
Target Milestone: 6.8.0
Assignee: Evgeni Golov
QA Contact: Peter Ondrejka
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-09-14 11:09 UTC by Sayan Das
Modified: 2020-10-27 13:09 UTC (History)
1 user (show)

Fixed In Version: ansible-collection-redhat-satellite-1.3.0
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-10-27 13:09:00 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github theforeman foreman-ansible-modules pull 953 0 None closed scope image lookups in host module by the CR 2021-01-18 13:55:39 UTC
Red Hat Product Errata RHSA-2020:4366 0 None None None 2020-10-27 13:09:16 UTC

Description Sayan Das 2020-09-14 11:09:24 UTC
Description of problem:

Unable to check the information about resource "images" or build a host by spcifying "image" keyword with "hosts" module from Satellite Ansible collections.


Version-Release number of selected component (if applicable):
Red Hat Satellite 6.7

How reproducible:
Always

Steps to Reproduce:
1. Create a basic satellite setup with HG\CR\CP\DHCP\TFTP\DNS etc configured.
2. Create a image in satellite UI inside the compute resource using the existing templates in your Vmware infra.
3. Create a ansible playbook using Satellite Ansible collections as displayed below to either check the information about "images" or perform a "image" based deployment and execute the same.
~~~
    - name: Get image resources
      redhat.satellite.resource_info:
        username: "{{ satellite_username }}"
        password: "{{ satellite_password }}"
        server_url: "{{ satellite_url }}"
        organization: "{{ satellite_organization }}"
        resource: images
      register: images
      ignore_errors: true

    - debug: var=images


    - name: Create a host
      redhat.satellite.host:
        username: "{{ satellite_username }}"
        password: "{{ satellite_password }}"
        server_url: "{{ satellite_url }}"
        organization: "{{ satellite_organization }}"
        name: "testhost.example.com"
        location: "GSS"
        hostgroup: "satellite_image"
        build: true
        compute_profile: "Vmware-Satellite"
        compute_resource: "optimus"
        provision_method: "image"
        image: "RHEL7.8"
        state: present
      register: build


    - debug: var=build  
~~~

Actual results:
~~
$ ansible-playbook test.yaml -k --vault-password-file .vault 
SSH password: 
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [Test hosts modules for image based build] *****************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [satellite.example.com]

TASK [Set few facts.] *******************************************************************************************************************************************************************
ok: [satellite.example.com]

TASK [Get image resources] **************************************************************************************************************************************************************
fatal: [satellite.example.com]: FAILED! => changed=false 
  msg: 'Failed to list resource: "missing param ''operatingsystem_id'' in parameters"'
...ignoring

TASK [debug] ****************************************************************************************************************************************************************************
ok: [satellite.example.com] => 
  images:
    changed: false
    failed: true
    msg: 'Failed to list resource: "missing param ''operatingsystem_id'' in parameters"'

TASK [Create a host] ********************************************************************************************************************************************************************
fatal: [satellite.example.com]: FAILED! => changed=false 
  msg: 'Failed to list resource: "missing param ''operatingsystem_id'' in parameters"'

PLAY RECAP ******************************************************************************************************************************************************************************
satellite.example.com : ok=4    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=1   
~~

Expected results:

The module should be able to find the image by looking inside associated compute resource and then the host build should be submitted successfully.


Additional info:

* From my prospective in both of the scenarios, It seems when the host modules tries to look for the image resource, It's not looking for the same inside "compute resource". 

* To demonstrate further via hammer,

hammer> compute-resource image list --compute-resource optimus
---|---------|------------------|----------|--------------------------------------|----------
ID | NAME    | OPERATING SYSTEM | USERNAME | UUID                                 | USER DATA
---|---------|------------------|----------|--------------------------------------|----------
1  | RHEL7.8 | RHEL Server 7.8  | root     | 50001356-2221-54b5-a3af-94dadaad981b | false    
---|---------|------------------|----------|--------------------------------------|----------

hammer> compute-resource image info --name "RHEL7.8"
missing param 'operatingsystem_id' in parameters


hammer> compute-resource image info --name "RHEL7.8" --compute-resource optimus
Id:               1
Name:             RHEL7.8
Operating System: RHEL Server 7.8
Username:         root
UUID:             50001356-2221-54b5-a3af-94dadaad981b
User Data:        false
Architecture:     x86_64
Created at:       2020/06/23 16:22:34



Updated at:       2020/08/25 05:49:48

Comment 2 Evgeni Golov 2020-09-14 13:12:25 UTC
can you try the following patch against the host module?


diff --git plugins/modules/host.py plugins/modules/host.py
index 99ec2d07..e96110f8 100644
--- plugins/modules/host.py
+++ plugins/modules/host.py
@@ -221,7 +221,7 @@ def main():
             owner_group=dict(type='entity', resource_type='usergroups', flat_name='owner_id'),
             owner_type=dict(type='invisible'),
             provision_method=dict(choices=['build', 'image', 'bootdisk']),
-            image=dict(type='entity'),
+            image=dict(type='entity', scope=['compute_resource']),
             compute_attributes=dict(type='dict'),
         ),
         mutually_exclusive=[

Comment 3 Sayan Das 2020-09-14 13:33:13 UTC
Hello Evgeni,

Yes, that change works fine now. I can get the host created now.

$ diff collections/ansible_collections/redhat/satellite/plugins/modules/host.py collections/ansible_collections/redhat/satellite/plugins/modules/host.py_bkp
191c191
<             image=dict(type='entity', scope=['compute_resource']),
---
>             image=dict(type='entity'),


This resource_info module still fails to list the images with following task.
~~
    - name: Get image resources
      redhat.satellite.resource_info:
        username: "{{ satellite_username }}"
        password: "{{ satellite_password }}"
        server_url: "{{ satellite_url }}"
        organization: "{{ satellite_organization }}"
        resource: images
      register: images
      ignore_errors: true
~~

Am i missing something in the task ?

Comment 4 Evgeni Golov 2020-09-14 13:43:53 UTC
(In reply to Sayan Das from comment #3)

> This resource_info module still fails to list the images with following task.
> ~~
>     - name: Get image resources
>       redhat.satellite.resource_info:
>         username: "{{ satellite_username }}"
>         password: "{{ satellite_password }}"
>         server_url: "{{ satellite_url }}"
>         organization: "{{ satellite_organization }}"
>         resource: images
>       register: images
>       ignore_errors: true
> ~~
> 
> Am i missing something in the task ?

Yeah. So "image" objects can't be searched "as is". You need to search them scoped by another entity (that's also what the patch for the host module does, it tells our library "go, search by compute_resource"). resource_info is a rather "dumb" module, so it doesn't know that, and just throws an error at you "missing param ''operatingsystem_id'' in parameters"

Now images can be scoped by three things: operatingsystems, architectures and compute_resources. I must admit scoping them by OS or arch is rather confusing, so both the "image" module and the "host" module (after the above patch) forces scoping by CR. To do the same with "resource_info", you could do smth like that:

    - name: Get image resources
      redhat.satellite.resource_info:
        username: "{{ satellite_username }}"
        password: "{{ satellite_password }}"
        server_url: "{{ satellite_url }}"
        organization: "{{ satellite_organization }}"
        resource: images
        params:
          compute_resource_id: 1234
      register: images

You'd obviously need to know the numeric ID of the CR, which you can find using… resource_info ;)

FWIW, we (eng) don't consider that a bug in resource_info, but there is a long term goal to have specific _info modules for individual entities. <insert something about finite time problems here> ;)

Comment 12 errata-xmlrpc 2020-10-27 13:09:00 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 (Important: Satellite 6.8 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-2020:4366


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