oravirt/ansible-oracle-modules

Error using state: absent in oracle_grant module

Closed this issue · 6 comments

Here is my playbook
tasks:
- name: This playbook will create the user.
oracle_grants:
user: "{{user}}"
password: "{{password}}"
service_name: "{{sname}}"
port: "{{prt}}"
hostname: "{{hostname}}"
schema: TSTSCH

grants: "'DBA','create session','create any table',connect,resource"

    grants: 'create session'
    state: absent
  environment: "{{oracle_env}}"
  register: user_grants
  delegate_to: localhost

I am getting the below error

The full traceback is:
Traceback (most recent call last):
File "/home/ansible/.ansible/tmp/ansible-tmp-1580220579.04-228603469188212/AnsiballZ_oracle_grants", line 102, in
_ansiballz_main()
File "/home/ansible/.ansible/tmp/ansible-tmp-1580220579.04-228603469188212/AnsiballZ_oracle_grants", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/ansible/.ansible/tmp/ansible-tmp-1580220579.04-228603469188212/AnsiballZ_oracle_grants", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.oracle_grants', init_globals=None, run_name='main', alter_sys=True)
File "/usr/lib64/python2.7/runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/tmp/ansible_oracle_grants_payload_GK4fah/ansible_oracle_grants_payload.zip/ansible/modules/oracle_grants.py", line 673, in
File "/tmp/ansible_oracle_grants_payload_GK4fah/ansible_oracle_grants_payload.zip/ansible/modules/oracle_grants.py", line 646, in main
TypeError: remove_grants() takes exactly 7 arguments (6 given)

fatal: [22.174.101.30 -> localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File "/home/ansible/.ansible/tmp/ansible-tmp-1580220579.04-228603469188212/AnsiballZ_oracle_grants", line 102, in \n _ansiballz_main()\n File "/home/ansible/.ansible/tmp/ansible-tmp-1580220579.04-228603469188212/AnsiballZ_oracle_grants", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/ansible/.ansible/tmp/ansible-tmp-1580220579.04-228603469188212/AnsiballZ_oracle_grants", line 40, in invoke_module\n runpy.run_module(mod_name='ansible.modules.oracle_grants', init_globals=None, run_name='main', alter_sys=True)\n File "/usr/lib64/python2.7/runpy.py", line 176, in run_module\n fname, loader, pkg_name)\n File "/usr/lib64/python2.7/runpy.py", line 82, in _run_module_code\n mod_name, mod_fname, mod_loader, pkg_name)\n File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code\n exec code in run_globals\n File "/tmp/ansible_oracle_grants_payload_GK4fah/ansible_oracle_grants_payload.zip/ansible/modules/oracle_grants.py", line 673, in \n File "/tmp/ansible_oracle_grants_payload_GK4fah/ansible_oracle_grants_payload.zip/ansible/modules/oracle_grants.py", line 646, in main\nTypeError: remove_grants() takes exactly 7 arguments (6 given)\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

Hi,

You don’t really need to use state: absent with this module. Just specify the grants that you want and the module will figure out the rest.
So if you don’t the schema to have create session, just remove it from the list.

I’m thinking about removing the state directive altogether, but I haven’t decided yet..

I’ll fix this error though.

Thanks very much. I will remove the state from my playbook.

For now, keep the state but set it to present

My use case is, I have 5 users, all 5 users will have different grants, But I want to revoke only one grant that is common in all the 5 users. How do I do that ? If I have keep state: present, this revokes all the grants the user has and gives only the grant parameter has.

If you want this module to manage the grants of these users, then you create a list of the users with their individual grants and run the module against that list.

e.g
If w is the grant that is 'shared' across all users, just comment it out (or remove from the list) and then it will be removed from all users

- myusers:
       - name: user1
          grants:
               - a
               - b
               #- w
       - name: user2
          grants:
               - c
               - d
               - e
              # - w
      - name: user3
          grants:
               - f
               - g
               - h
              # - w
       - name: user4
          grants:
               - i
               - j
               - k
              # - w
        - name: user5
          grants:
               - l
               - m
               - n
               #- w

Thanks very much