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: does not support scoped search #338

Closed jwbernin closed 4 years ago

jwbernin commented 5 years ago
SUMMARY

When I try to retrieve a list of Products using foreman_search_facts, it either complains that a required parameter is missing (organization_id), or complains that an unsupported parameter was provided (organization_id).

ISSUE TYPE
ANSIBLE VERSION
$ ansible --version
ansible 2.8.0
  config file = /nfshome/jberning/ansible/ansible.cfg
  configured module search path = ['/nfshome/jberning/Projects/foreman-ansible-modules/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Apr  3 2019, 17:26:03) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]
KATELLO/FOREMAN VERSION
tfm-rubygem-katello-3.10.0.46-1.el7sat.noarch
foreman-1.20.1.34-1.el7sat.noarch
NAILGUN VERSION
$ pip3 show nailgun | grep Version
Version: 0.32.0
STEPS TO REPRODUCE
---
- name: enable repos on Satellite
  hosts: localhost
  vars:
    satellite_host: newsat.ncphotography.lan
    satellite_user: admin
    satellite_password: admin
    org_id: 1
  tasks:
    - name: Get all Products
      foreman_search_facts:
        username: "{{ satellite_user }}"
        password: "{{ satellite_password }}"
        server_url: "https://{{ satellite_host }}"
        verify_ssl: false
        resource: products
  register: products

OR

---
- name: enable repos on Satellite
  hosts: localhost
  vars:
    satellite_host: newsat.ncphotography.lan
    satellite_user: admin
    satellite_password: admin
    org_id: 1
  tasks:
    - name: Get all Products
      foreman_search_facts:
        username: "{{ satellite_user }}"
        password: "{{ satellite_password }}"
        server_url: "https://{{ satellite_host }}"
        verify_ssl: false
        resource: products
        organization_id: "{{ org_id }}"
    register: products
EXPECTED RESULTS

One of the two plays would work as expected

ACTUAL RESULTS

First play: fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to list resource: The following required parameters are missing: organization_id"}

Second play: fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (foreman_search_facts) module: organization_id Supported parameters include: password, resource, search, server_url, username, validate_certs"}

evgeni commented 5 years ago

I think you can pass search: "organization_id={{ org_id }}" as an workaround.

Bit of background: product is a Katello object, and those are always scoped to an Org, but foreman_search_facts currently does not support scoped searches

jwbernin commented 5 years ago

Adding a search has no effect, I get the same combination of errors.

evgeni commented 4 years ago

@jwbernin mind testing the fix in #537, whether it helps your case (or not)?

jwbernin commented 4 years ago

That fix does indeed fix my use case.

mdellweg commented 4 years ago

Shall we close this one, or recycle to implement better support for scoping with taxonomy, products, ...?

mdellweg commented 4 years ago

Closing in favour of #570