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

theforeman.foreman.smart_proxy module -> download_policy: background looks broken

Open lpther opened this issue 2 years ago • 2 comments

SUMMARY

Changing the download_policy of the smart_proxy to "background" results in an error.

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
ansible [core 2.13.0]
  config file = /home/lpt069/workspace/svc_baseos_provisioning/ansible.cfg
  configured module search path = ['/home/lpt069/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/lpt069/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/lpt069/.ansible/collections:/home/lpt069/workspace/svc_baseos_provisioning_includes:/home/lpt069/workspace/svc_baseos_provisioning
  executable location = /home/lpt069/.local/bin/ansible
  python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
  jinja version = 3.1.1
  libyaml = True
COLLECTION VERSION
# /home/lpt069/.ansible/collections/ansible_collections
Collection            Version
--------------------- -------
ansible.posix         1.3.0  
community.general     5.0.0  
theforeman.foreman    3.4.0  
theforeman.operations 1.2.0  
KATELLO/FOREMAN VERSION
[vagrant@foreman-server ~]$ rpm -q tfm-rubygem-katello foreman
package tfm-rubygem-katello is not installed
foreman-3.2.1-1.el8.noarch

STEPS TO REPRODUCE
vars:
failed: [localhost] (item={'key': 'foreman-proxy.example.com', 'value': {'organizations': ['default_organization', 'test_organization'], 'locations': ['default_location', 'test_location'], 'download_policy': 'background'}}) => changed=false 

task:
- name: Configure foreman smart proxies
  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: "{{ item['key'] }}"
    url: "https://{{ item['key'] }}:9090"
    locations: "{{ item['value']['locations'] | default(omit) }}"
    organizations: "{{ item['value']['organizations'] | default(omit) }}"
    download_policy: "{{ item['value']['download_policy'] | default(omit) }}"
  loop: "{{ foreman_helper__smart_proxy | dict2items }}"

EXPECTED RESULTS

download_policy set to background

ACTUAL RESULTS

Note that it works for "immediate". Setting it to "inherited" as in the error message does not work also.

<127.0.0.1> EXEC /bin/sh -c 'echo ~lpt069 && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/lpt069/.ansible/tmp `"&& mkdir "` echo /home/lpt069/.ansible/tmp/ansible-tmp-1654089459.1753192-2353212-218802452099624 `" && echo ansible-tmp-1654089459.1753192-2353212-218802452099624="` echo /home/lpt069/.ansible/tmp/ansible-tmp-1654089459.1753192-2353212-218802452099624 `" ) && sleep 0'
Using module file /home/lpt069/.ansible/collections/ansible_collections/theforeman/foreman/plugins/modules/smart_proxy.py
<127.0.0.1> PUT /home/lpt069/.ansible/tmp/ansible-local-23520644tndk103/tmpjppi7wxg TO /home/lpt069/.ansible/tmp/ansible-tmp-1654089459.1753192-2353212-218802452099624/AnsiballZ_smart_proxy.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/lpt069/.ansible/tmp/ansible-tmp-1654089459.1753192-2353212-218802452099624/ /home/lpt069/.ansible/tmp/ansible-tmp-1654089459.1753192-2353212-218802452099624/AnsiballZ_smart_proxy.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/lpt069/.ansible/tmp/ansible-tmp-1654089459.1753192-2353212-218802452099624/AnsiballZ_smart_proxy.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/lpt069/.ansible/tmp/ansible-tmp-1654089459.1753192-2353212-218802452099624/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_theforeman.foreman.smart_proxy_payload_y4uxsitb/ansible_theforeman.foreman.smart_proxy_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 1206, in resource_action
    result = self._resource_call(resource, action, resource_payload, options=options, data=data, files=files)
  File "/tmp/ansible_theforeman.foreman.smart_proxy_payload_y4uxsitb/ansible_theforeman.foreman.smart_proxy_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 682, in _resource_call
    return self._resource(resource).call(*args, **kwargs)
  File "/tmp/ansible_theforeman.foreman.smart_proxy_payload_y4uxsitb/ansible_theforeman.foreman.smart_proxy_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/_apypie.py", line 864, in call
    return self.api.call(self.name, action, params, headers, options, data, files)
  File "/tmp/ansible_theforeman.foreman.smart_proxy_payload_y4uxsitb/ansible_theforeman.foreman.smart_proxy_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/_apypie.py", line 482, in call
    return self._call_action(action, params, headers, data, files)
  File "/tmp/ansible_theforeman.foreman.smart_proxy_payload_y4uxsitb/ansible_theforeman.foreman.smart_proxy_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/_apypie.py", line 490, in _call_action
    return self.http_call(
  File "/tmp/ansible_theforeman.foreman.smart_proxy_payload_y4uxsitb/ansible_theforeman.foreman.smart_proxy_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/_apypie.py", line 532, in http_call
    request.raise_for_status()
  File "/home/lpt069/.local/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
failed: [localhost] (item={'key': 'foreman-proxy.example.com', 'value': {'organizations': ['default_organization', 'test_organization'], 'locations': ['default_location', 'test_location'], 'download_policy': 'background'}}) => changed=false 
  ansible_loop_var: item
  error:
    errors:
      download_policy:
      - 'must be one of the following: on_demand, immediate, inherit'
    full_messages:
    - 'Download policy must be one of the following: on_demand, immediate, inherit'
    id: 2
  invocation:
    module_args:
      download_policy: background
      lifecycle_environments: null
      locations:
      - default_location
      - test_location
      name: foreman-proxy.example.com
      organizations:
      - default_organization
      - test_organization
      password: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      server_url: https://127.0.0.1:60443/
      state: present
      url: https://foreman-proxy.example.com:9090
      username: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
      validate_certs: false
  item:
    key: foreman-proxy.example.com
    value:
      download_policy: background
      locations:
      - default_location
      - test_location
      organizations:
      - default_organization
      - test_organization
  msg: 'Error while performing update on smart_proxies: 422 Client Error: Unprocessable Entity for url: https://127.0.0.1:60443/api/smart_proxies/2'

lpther avatar Jun 01 '22 13:06 lpther

Well, that is a documentation error in the module. There is no option "background" anymore. This option has been deprecated with Katello 4.0. As the message says:

      - 'must be one of the following: on_demand, immediate, inherit'

gvde avatar Jun 01 '22 14:06 gvde

Created pull request #1424

gvde avatar Jun 01 '22 15:06 gvde

This was fixed in 6c919dd5ccb3ad8303c74d5e3836274a9c929642 and https://github.com/theforeman/foreman-ansible-modules/commit/42a0d79706938111c62be8375d692d14d30bab8c

evgeni avatar Sep 23 '22 09:09 evgeni