Closed trbs closed 6 years ago
@trbs
Thanks for looking into this. Do you have an example playbook for testing?
I'm wondering, since the playbook is in check mode, why the module would be calling the create
method at all.
The only reason I can think of that it does call self._create
instead of doing an if not self.check_mode:
is that request_body = self.helper.request_body_from_params(self.params)
gets called. Which if it would raise an exception would show up during checkmode.
Otherwise I'm happy to change the PR to do another if not self.check_mode:
instead.
Looking at line 204 (if existing and force:
) that will have the some problem in check_mode
where k8s_obj
will be None.
Example Playbook:
---
- hosts: localhost
remote_user: root
gather_facts: false
roles:
- role: ansible.kubernetes-modules
install_python_requirements: no
tasks:
- name: Basic-User Cluster Role Bindings
k8s_v1beta1_cluster_role_binding:
context: "{{ k8s_context }}"
name: "basic-user:{{ item }}"
role_ref_api_group: rbac.authorization.k8s.io
role_ref_kind: ClusterRole
role_ref_name: "system:basic-user"
subjects:
- name: "{{ item }}"
kind: User
state: present
with_items:
- trbs
Yields:
PLAY [localhost] *****************************************************************************************************************************
TASK [ansible.kubernetes-modules : Install latest openshift client] **************************************************************************
skipping: [localhost]
TASK [Basic-User Cluster Role Bindings] ******************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'to_dict'
failed: [localhost] (item=trbs) => {"changed": false, "item": "trbs", "module_stderr": "Traceback (most recent call last):\n File \"/var/folders/gj/07k6rt111v39_0hzth5gzybh0000gn/T/ansible_haeuvepn/ansible_module_k8s_v1beta1_cluster_role_binding.py\", line 207, in <module>\n main()\n File \"/var/folders/gj/07k6rt111v39_0hzth5gzybh0000gn/T/ansible_haeuvepn/ansible_module_k8s_v1beta1_cluster_role_binding.py\", line 201, in main\n module.execute_module()\n File \"/var/folders/gj/07k6rt111v39_0hzth5gzybh0000gn/T/ansible_haeuvepn/ansible_modlib.zip/ansible/module_utils/k8s_common.py\", line 201, in execute_module\nAttributeError: 'NoneType' object has no attribute 'to_dict'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
@chouseknecht good to merge?
when in checkmode _create returns None and cannot have to_dict() called