ansible-collections / community.kubernetes

Kubernetes Collection for Ansible
https://galaxy.ansible.com/community/kubernetes
GNU General Public License v3.0
265 stars 104 forks source link

missing 1 required positional argument: 'body' #371

Closed emersonramos closed 3 years ago

emersonramos commented 3 years ago
SUMMARY

I'm using community.kubernetes modules to create any rolebindings using a template.

ISSUE TYPE

Error message:

{
    "module_stdout": "",
    "module_stderr": "Traceback (most recent call last):\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.kubernetes.plugins.modules.k8s', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/modules/k8s.py\", line 337, in <module>\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/modules/k8s.py\", line 333, in main\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/module_utils/common.py\", line 605, in execute_module\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/module_utils/common.py\", line 670, in perform_action\nTypeError: get() missing 1 required positional argument: 'body'\n",
    "exception": "Traceback (most recent call last):\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.kubernetes.plugins.modules.k8s', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/modules/k8s.py\", line 337, in <module>\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/modules/k8s.py\", line 333, in main\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/module_utils/common.py\", line 605, in execute_module\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/module_utils/common.py\", line 670, in perform_action\nTypeError: get() missing 1 required positional argument: 'body'\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
COMPONENT NAME

common.py

ANSIBLE VERSION
ansible 2.9.13
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Aug 18 2020, 08:33:21) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
CONFIGURATION
OS / ENVIRONMENT

Red Hat Enterprise Linux release 8.3 (Ootpa)

STEPS TO REPRODUCE

I'm using ansible tower. I'm using a template to apply rolebindings. I was using 1.1.1 version and it's working fine. I don't know why, I get this error. I tried to update to 1.2.0, but it's not solved.


---
- name: "Create Rolebindings"
  hosts: all
  vars_files:
    - "defaults/secret.yml"    
  gather_facts: false
  vars:
    ansible_python_interpreter: /usr/bin/python3

  module_defaults:
    community.kubernetes.k8s:
      state: 'present'
      host: "https://<url>:6443"
      api_key: "{{ SECRET.TOKEN }}"
      validate_certs: no

  tasks:
  - name: Create defaults rolebindings
    community.kubernetes.k8s:
      state: present
      template: 'bp_default-bindings.j2'
    loop:
      - { group_name: 'Openshift_{{ var_ambiente[0]|upper }}{{ var_ambiente[1:] }}_Arch', role_name: 'bp_arc_{{ var_ambiente }}' }
      - { group_name: 'Openshift_{{ var_ambiente[0]|upper }}{{ var_ambiente[1:] }}_Aud', role_name: 'bp_aud_{{ var_ambiente }}' }

J2

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: "{{ item.role_name }}-{{ item.group_name }}"
  namespace: "bp-{{ nome_namespace }}-{{ var_ambiente }}"
subjects:
  - kind: Group
    apiGroup: rbac.authorization.k8s.io
    name: "{{ item.group_name }}"
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: "{{ item.role_name }}"
EXPECTED RESULTS

Turn to create rolebindings again

ACTUAL RESULTS

{
    "module_stdout": "",
    "module_stderr": "Traceback (most recent call last):\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.kubernetes.plugins.modules.k8s', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/modules/k8s.py\", line 337, in <module>\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/modules/k8s.py\", line 333, in main\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/module_utils/common.py\", line 605, in execute_module\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/module_utils/common.py\", line 670, in perform_action\nTypeError: get() missing 1 required positional argument: 'body'\n",
    "exception": "Traceback (most recent call last):\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1614365944.6865492-9-58089201719527/AnsiballZ_k8s.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.kubernetes.plugins.modules.k8s', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/modules/k8s.py\", line 337, in <module>\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/modules/k8s.py\", line 333, in main\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/module_utils/common.py\", line 605, in execute_module\n  File \"/tmp/ansible_community.kubernetes.k8s_payload_if44_923/ansible_community.kubernetes.k8s_payload.zip/ansible_collections/community/kubernetes/plugins/module_utils/common.py\", line 670, in perform_action\nTypeError: get() missing 1 required positional argument: 'body'\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "_ansible_no_log": false,
    "changed": false,
    "item": {
        "group_name": "Openshift_Dev_Arch",
        "role_name": "bp_arc_dev"
    },
    "ansible_loop_var": "item",
    "_ansible_item_label": {
        "group_name": "Openshift_Dev_Arch",
        "role_name": "bp_arc_dev"
    }
}
Akasurde commented 3 years ago

I am not able to reproduce

changed: [localhost] => (item={'group_name': 'Openshift_Av_Arch', 'role_name': 'bp_arc_av'}) => {"ansible_loop_var": "item", "changed": true, "item": {"group_name": "Openshift_Av_Arch", "role_name": "bp_arc_av"}, "method": "create", "result": {"apiVersion": "rbac.authorization.k8s.io/v1", "kind": "RoleBinding", "metadata": {"creationTimestamp": "2021-02-28T15:00:15Z", "name": "bp_arc_av-Openshift_Av_Arch", "namespace": "default", "resourceVersion": "8073020", "selfLink": "/apis/rbac.authorization.k8s.io/v1/namespaces/default/rolebindings/bp_arc_av-Openshift_Av_Arch", "uid": "6a1af9fd-4eba-40b6-b2ee-8b4a067a5bcf"}, "roleRef": {"apiGroup": "rbac.authorization.k8s.io", "kind": "ClusterRole", "name": "bp_arc_av"}, "subjects": [{"apiGroup": "rbac.authorization.k8s.io", "kind": "Group", "name": "Openshift_Av_Arch"}]}}
changed: [localhost] => (item={'group_name': 'Openshift_Av_Aud', 'role_name': 'bp_aud_av'}) => {"ansible_loop_var": "item", "changed": true, "item": {"group_name": "Openshift_Av_Aud", "role_name": "bp_aud_av"}, "method": "create", "result": {"apiVersion": "rbac.authorization.k8s.io/v1", "kind": "RoleBinding", "metadata": {"creationTimestamp": "2021-02-28T15:00:16Z", "name": "bp_aud_av-Openshift_Av_Aud", "namespace": "default", "resourceVersion": "8073025", "selfLink": "/apis/rbac.authorization.k8s.io/v1/namespaces/default/rolebindings/bp_aud_av-Openshift_Av_Aud", "uid": "e1dbc251-6f5b-4682-b29d-1a27a44fa372"}, "roleRef": {"apiGroup": "rbac.authorization.k8s.io", "kind": "ClusterRole", "name": "bp_aud_av"}, "subjects": [{"apiGroup": "rbac.authorization.k8s.io", "kind": "Group", "name": "Openshift_Av_Aud"}]}}
# ansible-galaxy collection list | grep kuber
community.kubernetes                     1.2.0

I am trying other things to reproduce this.

emersonramos commented 3 years ago

It's crazy because I have no changes on my environment.

I tried upgrade to 1.2.0, but I get same error.

emersonramos commented 3 years ago

I find out a difference between success and error logs.

On success, the module search patch is:

ansible-playbook 2.9.13 config file = /etc/ansible/ansible.cfg configured module search path = ['/var/lib/awx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

On error logs, I get:

ansible-playbook 2.9.13 config file = /etc/ansible/ansible.cfg configured module search path = ['/var/lib/awx/venv/awx/lib64/python3.6/site-packages/awx/plugins/library']

I don't know why this difference.

tima commented 3 years ago

In the error, your system is only looking in the module content that ships with AWX itself while the success runs is looking in modules (collections) installed into AWX and the system Ansible that presumably includes the latest version of this collection.

I'm pretty sure that is where your problem is at -- something is changing/overriding in your Tower system configuration search path. I'd recommend contacting Red Hat support for assistance if you can't figure out what's changing your system configuration.