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

foreman_search_facts: add params option #523

Closed nesanton closed 4 years ago

nesanton commented 4 years ago
SUMMARY

It's not possible to specify params that GET API calls for different resources may have. Sometimes these params are required which makes the module fail. E.g. with resource: content_view_filters it fails with "content_view_id is required". Since search can't be performed for content_view_filters using search: content_view_id=189, it's impossible to use this module to list content_view_filters.

Suggestion: add params option that would acceps a dictionary of arbitrary parameters.

- name: Ensure CV exists
  katello_content_view:
    other_stuff: blah
    name: cv1
  register: cv

- name: Search for CV filters of cv1
  foreman_search_facts:
    other_stuff: blah
    resource: content_view_filters
    params:
       content_view_id: "{{ cv.entity.id }}"
 register: all_cv1_filters

This module uses list_resource function https://github.com/theforeman/foreman-ansible-modules/blob/362161115f693cd8e7bda10c98ff9f82a64cbfa4/plugins/modules/foreman_search_facts.py#L119

that does accept params, which are supposedly exactly what we need. Should be easy to add.

ISSUE TYPE
evgeni commented 4 years ago

is this (technically) a dupe of https://github.com/theforeman/foreman-ansible-modules/issues/338?