Repository: ansible/ansible

Issue:
openshift_raw cannot create RoleBinding resources
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
openshift_raw

##### ANSIBLE VERSION
```
ansible 2.5.0rc1 (stable-2.5 409193a7dc) last updated 2018/02/28 00:06:40 (GMT +200)
  config file = /Users/twhiston/.ansible.cfg
  configured module search path = [u'/Users/twhiston/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/devel/lib/ansible
  executable location = /usr/local/Cellar/ansible/devel/bin/ansible
  python version = 2.7.10 (default, Jul 15 2017, 17:16:57) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]

```

##### OS / ENVIRONMENT
N/A

##### SUMMARY

Attempting to create a rolebinding fails because the Openshift Python Module does not support the roleRef key, which is a required field for a rolebinding

##### STEPS TO REPRODUCE
```yaml
- name: Bind roles to groups
  openshift_raw:
    host: "{{ openshift_host }}"
    api_version: v1
    api_key: "{{ oc_token }}"
    verify_ssl: "{{ verify_ssl }}"
    definition: "{{ lookup('template', '../files/rolebinding.yml') | from_yaml }}"
    state: present
  with_items:
    - admin
    - edit
    - view
```

Resource file
```yaml
apiVersion: v1
groupNames:
- "{{ project_name }}-{{ item }}"
kind: RoleBinding
metadata:
  name: "{{ item }}"
  namespace: "{{ project_name }}"
roleRef:
  name: "{{ item }}"
subjects:
- kind: Group
  name: "{{ project_name }}-{{ item }}"
```

##### EXPECTED RESULTS
Rolebind is created

##### ACTUAL RESULTS
```
failed: [localhost] (item=admin) => {"changed": false, "item": "admin", "msg": "Error parsing resource definition. Encountered roleRef_name, which does not map to a parameter expected by the OpenShift Python module."}
failed: [localhost] (item=edit) => {"changed": false, "item": "edit", "msg": "Error parsing resource definition. Encountered roleRef_name, which does not map to a parameter expected by the OpenShift Python module."}
failed: [localhost] (item=view) => {"changed": false, "item": "view", "msg": "Error parsing resource definition. Encountered roleRef_name, which does not map to a parameter expected by the OpenShift Python module."}
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/clustering/openshift/openshift_raw.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/clustering/openshift/openshift_raw.py)

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](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @chouseknecht @fabianvf @flaper87 @maxamillion @sdoran
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/module_utils/k8s/common.py b/lib/ansible/module_utils/k8s/common.py
--- a/lib/ansible/module_utils/k8s/common.py
+++ b/lib/ansible/module_utils/k8s/common.py
@@ -192,7 +192,7 @@ def resource_to_parameters(self, resource):
             elif key in self.helper.argspec and value is not None:
                 parameters[key] = value
             elif isinstance(value, dict):
-                self._add_parameter(value, [key], parameters)
+                self._add_parameter(value, [to_snake(key)], parameters)
         return parameters
 
     def _add_parameter(self, request, path, parameters):
@@ -200,12 +200,12 @@ def _add_parameter(self, request, path, parameters):
             if path:
                 param_name = '_'.join(path + [to_snake(key)])
             else:
-                param_name = self.helper.attribute_to_snake(key)
+                param_name = to_snake(key)
             if param_name in self.helper.argspec and value is not None:
                 parameters[param_name] = value
             elif isinstance(value, dict):
                 continue_path = copy.copy(path) if path else []
-                continue_path.append(self.helper.attribute_to_snake(key))
+                continue_path.append(to_snake(key))
                 self._add_parameter(value, continue_path, parameters)
             else:
                 self.fail_json(


Test patch: