Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openshift_raw does not honor K8S_* environment variables #43882

Closed
lcarva opened this issue Aug 9, 2018 · 6 comments
Closed

openshift_raw does not honor K8S_* environment variables #43882

lcarva opened this issue Aug 9, 2018 · 6 comments
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. deprecated This issue/PR relates to a deprecated module. k8s module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback.

Comments

@lcarva
Copy link

lcarva commented Aug 9, 2018

SUMMARY

When using the openshift_raw module, host and api token are not read from environment variables.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

openshift_raw

ANSIBLE VERSION
ansible 2.6.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/lucarval/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15 (default, May 15 2018, 15:37:31) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]
CONFIGURATION
OS / ENVIRONMENT

Fedora 27
Python OpenShift Rest Client: openshift (0.6.2)

STEPS TO REPRODUCE

This does not work:

- name: Create a project
  openshift_raw:
    api_version: v1
    kind: Project
    name: testing
    description: Testing
    display_name: "This is a test project."
    state: present
  environment:
    K8S_AUTH_API_KEY: "{{ ocp_token }}"
    K8S_AUTH_HOST: "{{ ocp_host }}"

However, this works just fine:

- name: Create a project
  openshift_raw:
    api_key: "{{ ocp_token }}"
    host: "{{ ocp_host }}"
    api_version: v1
    kind: Project
    name: testing
    description: Testing
    display_name: "This is a test project."
    state: present
EXPECTED RESULTS

Expected project to be created after connecting to cluster with values provided by the K8S_* environment variables.

ACTUAL RESULTS
Traceback (most recent call last):
  File "/tmp/ansible_9SCyO6/ansible_module_openshift_raw.py", line 165, in <module>
    main()
  File "/tmp/ansible_9SCyO6/ansible_module_openshift_raw.py", line 161, in main
    KubernetesRawModule().execute_module()
  File "/tmp/ansible_9SCyO6/ansible_modlib.zip/ansible/module_utils/k8s/raw.py", line 70, in execute_module
  File "/tmp/ansible_9SCyO6/ansible_modlib.zip/ansible/module_utils/k8s/common.py", line 167, in get_api_client
  File "/usr/lib/python2.7/site-packages/openshift/dynamic/client.py", line 58, in __init__
    self._load_server_info()
  File "/usr/lib/python2.7/site-packages/openshift/dynamic/client.py", line 62, in _load_server_info
    self.__version = {'kubernetes': load_json(self.request('get', '/version'))}
  File "/usr/lib/python2.7/site-packages/openshift/dynamic/client.py", line 255, in request
    _return_http_data_only=params.get('_return_http_data_only', True)
  File "/usr/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 321, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/usr/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 140, in __call_api
    self.update_params_for_auth(header_params, query_params, auth_settings)
  File "/usr/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 499, in update_params_for_auth
    auth_setting = self.configuration.auth_settings().get(auth)
  File "/usr/lib/python2.7/site-packages/kubernetes/client/configuration.py", line 228, in auth_settings
    'value': self.get_api_key_with_prefix('authorization')
  File "/usr/lib/python2.7/site-packages/kubernetes/client/configuration.py", line 202, in get_api_key_with_prefix
    if self.api_key.get(identifier) and self.api_key_prefix.get(identifier):
AttributeError: 'str' object has no attribute 'get'
@ansibot
Copy link
Contributor

ansibot commented Aug 9, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Aug 9, 2018

@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. deprecated This issue/PR relates to a deprecated module. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. labels Aug 9, 2018
@fabianvf
Copy link
Contributor

fabianvf commented Aug 9, 2018

I think this may be fixed in 2.6.2, issue was caused by API key not being properly formatted into an authorization header

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Aug 9, 2018
@fabianvf
Copy link
Contributor

There are some additional fixes for authorization parameters here; #44142

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Sep 16, 2018
@fabianvf
Copy link
Contributor

This should be fixed in 2.7 with #44142

@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 2, 2018
@dagwieers dagwieers added the k8s label Feb 8, 2019
@gundalow
Copy link
Contributor

#44142 has been merged, so closing

@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. deprecated This issue/PR relates to a deprecated module. k8s module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback.
Projects
None yet
Development

No branches or pull requests

5 participants