theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
GNU General Public License v3.0
147 stars 163 forks source link

Operating system media not inherited in nested hostgroups #1248

Open gardar opened 3 years ago

gardar commented 3 years ago
SUMMARY

When creating a nested hostgroup the installation media is not inherited from the parent group while other values such as architecture and operating system are inherited just fine.

This is actually the same that happens when you create a group in the gui, the installation media is not inherited when you create a nested group, but if you edit the group and save it again without making any changes the installation media gets populated. This however does not happen with the ansible module, if I run the task again it does not re save the group and thus does not populate the installation media in the same way as the guy action does.

I thought this was a bug in foreman/satellite but according to redhat this is the expected behavior: https://bugzilla.redhat.com/show_bug.cgi?id=1619257 so I think this is something that the module needs to handle.

ISSUE TYPE
ANSIBLE VERSION
ansible [core 2.11.0]
COLLECTION VERSION
theforeman.foreman 2.1.0
KATELLO/FOREMAN VERSION
tfm-rubygem-katello-3.18.1.29-1.2.el7sat.noarch
foreman-2.3.1.20-1.el7sat.noarch
STEPS TO REPRODUCE

Create a parent hostgroup that has a operating system version set and then create a child (nested) group that inherits the operating system values from the parent.

---                                                                                                     
- hosts: localhost 
  connection: local
  module_defaults: 
    theforeman.foreman.hostgroup: 
      username: "usr"                                                                            
      password: "psw" 
      server_url: "url" 
      validate_certs: "false"                                                                                                     
  tasks: 
    - name: "Update hostgroups"                                                  
      theforeman.foreman.hostgroup:                                              
        name: "{{ item.name }}"                                                  
        parent: "{{ item.parent | default(omit) }}"                              
        organization: "{{ item.organization }}"                                 
        locations: "{{ item.locations }}"                                        
        lifecycle_environment: "{{ item.lifecycle_environment | default(omit) }}"
        content_view: "{{ item.content_view | default(omit) }}"                  
        content_source: "{{ item.content_source | default(omit) }}"              
        pxe_loader: "{{ item.pxe_loader | default(omit) }}"                      
        architecture: "{{ item.architecture | default(omit) }}"                  
        operatingsystem: "{{ item.operatingsystem | default(omit) }}"            
        medium: "{{ item.medium | default(omit) }}"                              
        ptable: "{{ item.ptable | default(omit) }}"                              
        state: present                                                           
      loop:                                                                      
        - name: "grandparent"                                                
          organization: "myorg"                                            
          locations: "mylocation"                                                
        - name: "parent"                                                     
          parent: "grandparent"                                              
          organization: "myorg"                                            
          locations: "mylocation"                                                
          architecture: "x86_64"                                                 
          lifecycle_environment: Library                                         
          content_view: "RHEL 7"                                             
          content_source: "my.satellite.server"                               
          operatingsystem: "RedHat 7.9"                                          
          pxe_loader: "Grub2 UEFI"                                               
        - name: "child"                                                      
          parent: "grandparent/parent"                                   
          organization: "myorg"                                            
          locations: "mylocation"                                                
EXPECTED RESULTS

I expect to have three groups:

ACTUAL RESULTS

I get the following groups:

evgeni commented 3 years ago

I wonder if that's related to https://projects.theforeman.org/issues/32661 which was recently fixed.

But will try to reproduce regardless

wbclark commented 3 years ago

I believe this is the same issue as https://bugzilla.redhat.com/show_bug.cgi?id=1962386

paging @phess , let me know if you have some interest/bandwidth to look into it together :)

phess commented 3 years ago

I believe this is the same issue as https://bugzilla.redhat.com/show_bug.cgi?id=1962386

paging @phess , let me know if you have some interest/bandwidth to look into it together :)

Yes to interest, potential Yes to bandwidth. Thank you @wbclark for the offer! ;-)

omenos commented 1 year ago

Just wanted to voice that this is still an issue with the 3.9.0 version of the Ansible collection paired with Foreman 3.5.1. I generate a handful of nested hostgroups via Ansible without touching any installation media parameters except for Arch, OS, and PTable. Despite the UI showing the kickstart repository as selected in the Web UI as values provided from the lifecycle environment and content view, trying to provision any system with the theforeman.foreman.host module where build: true is set fails immediately. Example:

    - name: Create host in Foreman
      register: foreman_host
      theforeman.foreman.host:
        server_url: "{{ foreman_url }}"
        username: "{{ foreman_username }}"
        password: "{{ foreman_password }}"
        # organization: "example"
        # location: "{{ hostvars[inventory_hostname].location }}"
        name: "{{ inventory_hostname }}.example.com"
        hostgroup: "{{ hostvars[inventory_hostname].hostgroup }}"
        compute_profile: "{{ hostvars[inventory_hostname].compute_profile }}"
        build: true

This will first error out with:

FAILED! => {"changed": false, "msg": "Error while performing create on hosts: The following required parameters are missing: host[organization_id], host[location_id]"}

which after providing (un-commenting in the above) turns into this:

FAILED! => {"changed": false, "error": {"errors": {"medium_id": ["can't be blank"]}, "full_messages": ["Medium can't be blank"], "id": null}, "msg": "Error while performing create on hosts: 422 Client Error: Unprocessable Entity for url: https://foreman.example.com/api/hosts"}

Just going into the Web UI and "saving" each host group without making any modifications makes this go away...