Bug 1889951 - [RFE] Allow ansible_roles and inherited_ansible_roles in Host and HostGroup jail so it can be used in report templates
Summary: [RFE] Allow ansible_roles and inherited_ansible_roles in Host and HostGroup j...
Keywords:
Status: ASSIGNED
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Reporting
Version: 6.7.0
Hardware: All
OS: All
medium
medium
Target Milestone: 6.9.0
Assignee: Marek Hulan
QA Contact: Lukáš Hellebrandt
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-10-21 04:33 UTC by Sayan Das
Modified: 2020-11-07 01:18 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Foreman Issue Tracker 31260 Normal Ready For Testing Allow ansible_roles and inherited_ansible_roles in Host and HostGroup jail so it can be used in report templates 2020-11-25 05:11:38 UTC

Description Sayan Das 2020-10-21 04:33:38 UTC
1. Proposed title of this feature request

To be able to create and fetch reports for Hostgroups similar to what can be done for Hosts in Satellite 6.


2. What is the nature and description of the request?

This is an improvement RFE of an existing feature called "Report Templates". 

Right now, even though we have Class defined for "Hostgroup", we don't have any macro defined for hostgroup i.e. load_host_groups, similar to what we have for hosts i.e. load_hosts and that blocks the customer requirement.

So the additional macro needs to be defined along with some additions in "Allowed methods or members" for the "Hostgroup" class to achieve the result.


3. Why does the customer need this? (List the business requirements here)

The customer manages multiple parent-child hostgroups and uses ansible roles in them. It's required to have a report collected for the host groups to identify which host group has what ansible roles are defined and inherited from parents.

4. How would the customer like to achieve this? (List the functional requirements here)

The customer would like to be able to use a Custom report template in Satellite UI --> Monitor --> Report templates as displayed below, to get the desired results.
~~
<%#
name: Ansible Roles - HostGroup
snippet: false
model: ReportTemplate
-%>
<%- load_host_groups(search: '').each_record do |hg| -%>
<%-   report_row(
        'Hostgroup': hg.name,
        'Parent group': hg.parent,
        'Child group': hg.children,
        'roles': hg.ansible_roles,
        'inherited_roles': hg.inherited_ansible_roles
      ) -%>
<%- end -%>
<%= report_render -%>
~~


Since there is no macro present for hostgroup, we need the following change of code in place to have the above report template executed properly.
~~
# diff -u hostgroup.rb_original  /usr/share/foreman/app/models/hostgroup.rb
--- hostgroup.rb_original    2020-09-11 04:37:27.000000000 +0530
+++ /usr/share/foreman/app/models/hostgroup.rb    2020-10-21 07:45:30.254985686 +0530
@@ -99,10 +99,10 @@
   }

   class Jail < Safemode::Jail
-    allow :name, :diskLayout, :puppetmaster, :operatingsystem, :architecture,
+    allow :id, :name, :diskLayout, :puppetmaster, :operatingsystem, :architecture,
       :environment, :ptable, :url_for_boot, :params, :puppetproxy,
       :puppet_ca_server, :indent, :os, :arch, :domain, :subnet,
-      :subnet6, :realm, :root_pass, :description, :pxe_loader, :title
+      :subnet6, :realm, :root_pass, :description, :pxe_loader, :title, :ansible_roles, :inherited_ansible_roles, :children, :parent
   end

   # TODO: add a method that returns the valid os for a hostgroup


# diff -u base_template_scope_extensions.rb_original /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.14.0.31/app/lib/katello/concerns/base_template_scope_extensions.rb
--- base_template_scope_extensions.rb_original    2020-09-23 17:30:50.000000000 +0530
+++ /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.14.0.31/app/lib/katello/concerns/base_template_scope_extensions.rb    2020-10-21 07:22:00.300457415 +0530
@@ -8,7 +8,7 @@
           super + [:errata, :host_subscriptions, :host_applicable_errata_ids, :host_applicable_errata_filtered,
                    :host_latest_applicable_rpm_version, :load_pools, :load_errata_applications, :host_content_facet,
                    :host_sla, :host_products, :sub_name, :sub_sku, :registered_through, :last_checkin, :host_collections,
-                   :host_subscriptions_names, :host_subscriptions, :host_products_names, :host_collections_names]
+                   :host_subscriptions_names, :host_subscriptions, :host_products_names, :host_collections_names, :load_host_groups]
         end
       end

@@ -57,6 +57,10 @@
         host.host_collections.map(&:name)
       end

+      def load_host_groups(search: '', includes: nil, preload: nil)
+        load_resource(klass: Hostgroup, search: search, permission: 'view_hostgroups', includes: includes, preload: preload)
+      end
+
       def sub_name(pool)
         return unless pool
         pool.subscription&.name
~~


6. Is there already an existing RFE upstream or in Red Hat Bugzilla?

* Found upstream issue https://projects.theforeman.org/issues/28769 where the macro has been added for Hostgroup and many other attributes and this is fixed on foreman 2.1.0.

* But this upstream issue does not solve the problem as ansible_role related options are not whitelisted in the safe mode for the host group.


7. Does the customer have any specific timeline dependencies and which release would they like to target (i.e. RHEL5, RHEL6)?

The latest minor release of satellite 6.7 or upcoming release Satellite 6.8 or as soon as possible.


8. Is the sales team involved in this request and do they have any additional input?
No.


9. List any affected packages or components.
- tfm-rubygem-katello-3.14.0.31-1.el7sat.noarch (/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.14.0.31/app/lib/katello/concerns/base_template_scope_extensions.rb)
- foreman-1.24.1.28-3.el7sat.noarch (/usr/share/foreman/app/models/hostgroup.rb)


10. Would the customer be able to assist in testing this functionality if implemented?
Yes.


11. Additional information:

NA.

Comment 2 Marek Hulan 2020-10-21 08:02:56 UTC
The load_host_groups macro is added in Satellite 6.8, some of the allowed methods are not added to the Jail however. As you already figured, it's :ansible_roles, and :inherited_ansible_roles. Adding these two could be easily backported to the 6.8 branch. Should we change the title to allows these two methods in the safe mode and try to get it to the 6.8 stream?

Comment 3 Sayan Das 2020-10-21 08:06:07 UTC
(In reply to Marek Hulan from comment #2)
> The load_host_groups macro is added in Satellite 6.8, some of the allowed
> methods are not added to the Jail however. As you already figured, it's
> :ansible_roles, and :inherited_ansible_roles. Adding these two could be
> easily backported to the 6.8 branch. Should we change the title to allows
> these two methods in the safe mode and try to get it to the 6.8 stream?

My sat 6.8 instances died and hence I missed checking the macro's on 6.8 directly. 

I am good with your suggestions. Feel free to modify the BZ title as it seems correct.

Comment 6 Marek Hulan 2020-11-04 16:18:39 UTC
Created redmine issue https://projects.theforeman.org/issues/31260 from this bug

Comment 7 Bryan Kearney 2020-11-04 20:04:16 UTC
Upstream bug assigned to mhulan@redhat.com

Comment 8 Bryan Kearney 2020-11-04 20:04:18 UTC
Upstream bug assigned to mhulan@redhat.com


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