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: CLOSED ERRATA
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: 2021-04-21 13:18 UTC (History)
8 users (show)

Fixed In Version: tfm-rubygem-foreman_ansible-6.1.0
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-04-21 13:18:20 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 31260 0 Normal Closed Allow ansible_roles and inherited_ansible_roles in Host and HostGroup jail so it can be used in report templates 2021-02-16 11:07:21 UTC
Red Hat Product Errata RHSA-2021:1313 0 None None None 2021-04-21 13:18:42 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

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

Comment 9 Bryan Kearney 2021-01-06 16:20:57 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/31260 has been resolved.

Comment 10 Patrick Creech 2021-01-12 21:19:06 UTC
Marek, can we get this fix in a release of foreman-ansible?

Comment 11 Marek Hulan 2021-01-14 11:59:57 UTC
Adam, since you did the last release, could you please take a look as well? Thanks!

Comment 12 Adam Ruzicka 2021-01-14 12:58:04 UTC
Will do

Comment 13 Lukáš Hellebrandt 2021-03-22 14:46:11 UTC
Verified with Sat 6.9 snap 18.

The load_host_groups macro works and ansible_roles and inherited_ansible_roles methods are now accessible on both host objects and hostgroup objects.

Verified using the template from OP, verbatim, and a similar template changed for hosts (without parent and child methods).

Comment 16 errata-xmlrpc 2021-04-21 13:18:20 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


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