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
146 stars 163 forks source link

Get ansible roles via inventory plugin #1378

Open gardar opened 2 years ago

gardar commented 2 years ago
SUMMARY

With the ansible inventory plugin I would like to be able to group together in the hosts that have the same ansible role configured.

I can get the list of single hosts that have the ansible role applied with a host filter like this: host_filters: 'ansible_role="namespace.role"' but that does not include hosts that have the ansible role applied from a host group. This might be a limitation of the Satellite/Foreman api since the hosts overview in Satellite behaves the same.

Is there perhaps another way I could access this information?

To give you the context: I'm trying to use a ansible role in Satellite that's heavily dependent on ansible inventory groups for various things. Since the way Satellite/Foreman works with Ansible roles / variables is a bit different than Ansible does in general this has proven somewhat challenging but I could work around the issue with the inventory plugin if I could get a list of hosts that have the particular role applied.

ISSUE TYPE
Denney-tech commented 6 months ago

I think it would be awesome if the inventory plugin reported back the "foreman_ansible_roles" variable that is created by inventory_creator.rb, which appears to be exposed under /api/hosts/:id/ansible_roles and /api/hostgroups/:id/ansible_roles.