foreman-ansible-modules icon indicating copy to clipboard operation
foreman-ansible-modules copied to clipboard

theforeman.foreman.smart_proxy lifecycle_environments not working with duplicate LCEs names

Open lpther opened this issue 1 year ago • 3 comments

SUMMARY

Using the theforeman.foreman.smart_proxy lifecycle_environments parameter, having multiple lifecycle environments with the same name doesn't work.

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
ansible [core 2.13.3]
  config file = /data/home/lpt069/workspace/ansible.cfg
  configured module search path = ['/data/home/lpt069/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /data/home/lpt069/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /data/home/lpt069/.ansible/collections:/data/home/lpt069/workspace/ansible/collections
  executable location = /data/home/lpt069/.local/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION
# /data/home/lpt069/.ansible/collections/ansible_collections
Collection            Version
--------------------- -------
ansible.posix         1.3.0  
community.general     5.0.0  
community.vmware      2.6.0  
theforeman.foreman    3.4.0  
theforeman.operations 1.2.0  

KATELLO/FOREMAN VERSION
[root@foreman-dev1 ~]# rpm -q tfm-rubygem-katello foreman
package tfm-rubygem-katello is not installed
foreman-3.2.1-1.el8.noarch

STEPS TO REPRODUCE

Define two different organization
Add a smart proxy

- name: Add a lifecycle environment that is present multiple times
  theforeman.foreman.smart_proxy:
    username: "{{ foreman_helper__foreman_username }}"
    password: "{{ foreman_helper__foreman_password }}"
    server_url: "{{ foreman_helper__foreman_url }}"
    validate_certs: "{{ foreman_helper__foreman_validate_certs }}"
    name: proxy.example.com
    url: https://proxy.example.com:9090
    lifecycle_environments:
      - Library

EXPECTED RESULTS

Add all organization libraries to the smart proxy. Or even better, having a way to set the organization alongside the name like when doing the same via hammer:

hammer capsule content add-lifecycle-environment --name proxy.example.com --lifecycle-environment Library --organization Organization1

It seems to do a lookup on the LCEs name only, limiting how LCEs are defined (must use unique names) or simply preventing Library to be configured via Ansible.

ACTUAL RESULTS
failed: [proxy.example.com] (item=Configure smart proxy proxy.example.com) => changed=false 
  ansible_loop_var: item
  item:
    key: proxy.example.com
    value:
      download_policy: on_demand
      host_location: location1
      lifecycle_environments:
      - Library
      locations:
      - location1
      organizations:
      - Organization1
      - Organization2
      - Organization3
  msg: Found too many (3) results while searching for lifecycle_environments with name="Library"

lpther avatar Aug 24 '22 12:08 lpther

Why don't you set the organization in your playbook and loop through all orgs?

gvde avatar Aug 24 '22 14:08 gvde

Why don't you set the organization in your playbook and loop through all orgs?

The "organizations" parameter is a list of organizations the proxy is assigned to. Looping through it would make it non idempotent.

From what I understand it is not related to the lifecycle environments.

lpther avatar Aug 26 '22 01:08 lpther

Let me illustrate:

The organization parameter will set this association:

image

The lifecycle_environments parameter will associate the Name of the lifecycle environment, but cannot specify the Organization it belongs to. Making associating the Library or default_lifecycle_environment impossible via Ansible, since the LCE name is not unique.

image

An intuitive way to do so would be to pass a list of dict with the LCE name and Organization, instead of the LCE name only.

lpther avatar Aug 29 '22 14:08 lpther