IBM / ansible-for-i

the tool is to provide several customized modules for Ansible to manage IBM i systems.
GNU General Public License v3.0
54 stars 52 forks source link

Different stdout for ibmi_cl_command for CHKPRDOPT *OPSYS #165

Open syahrul-aiman opened 9 months ago

syahrul-aiman commented 9 months ago

Any idea why the different output result?

Sample task using command:

    - command: 'system "CHKPRDOPT *OPSYS"'
      register: chkprdopt
      ignore_errors: true

    - debug:
        var: chkprdopt.stdout

Output:

ok: [ibmi] => {
    "chkprdopt.stdout": "CPC0C20: No errors detected by CHKPRDOPT."
}

Sample task using ibmi_cl_command:

    - ibm.power_ibmi.ibmi_cl_command:
        cmd: "CHKPRDOPT *OPSYS DETAIL(*FULL)"
      register: chkprdopt
      ignore_errors: true

    - debug:
        var: dspusrprf.stdout

Output:

ok: [ibmi] => {
    "chkprdopt.stdout": "{'success': '+++ success CHKPRDOPT *OPSYS"
}

SSH terminal:

$ system "CHKPRDOPT *OPSYS"
CPC0C20: No errors detected by CHKPRDOPT.

Please advise on what I'm missing here.

syahrul-aiman commented 9 months ago

After checking this further, it is because of how the ibmi_cl_command treats the commands as system command (is_cmd5250) only if it starts with:

or exists OUTPUT(*) in the command

The command works if I add the following code after this line: https://github.com/IBM/ansible-for-i/blob/devel/plugins/modules/ibmi_cl_command.py#L194

    if command_upper.startswith('CHK'):
        is_cmd5250 = True

So for now, I need confirmation if all CHK and QSYS/CHK commands should be treated as 5250 command. If yes, then I'll help to perform the the code changes and do a PR.

I tried to add OUTPUT(*) at the end of the command. e.g.:

    - ibm.power_ibmi.ibmi_cl_command:
        cmd: "CHKPRDOPT *OPSYS DETAIL(*FULL) OUTPUT(*)"
      register: chkprdopt
      ignore_errors: true

    - debug:
        var: dspusrprf.stdout

But will get the following error:

CPD0043: Keyword OUTPUT not valid for this command.
CPF0006: Errors occurred in command.

Please advise.

syahrul-aiman commented 9 months ago

Another option is to allow explicit setting of is_cmd5250 to true

robgjertsen1 commented 8 months ago

Yes, currently the commands with OUTPUT and not having job log or become user capability (including DSP and WRK commands) follow one path with CL command and then the others such as CHKPRDOPT use iToolKit for command execution, so the output differs as a result. I would want to look into this further before making this type of change. I don't believe we would want to change this for all the CHK commands (consider CHKIN and CHKOUT) even if we went this route.

syahrul-aiman commented 8 months ago

Hi @robgjertsen1

If that's the case, do you think if the user can set the is_cmd5250 variable to true explicitly would be the viable option? If yes, I could help to do the code changes and PR for this.

It would be something like this:

def main():
    module = AnsibleModule(
        argument_spec=dict(
            cmd=dict(type='str', required=True),
### this line is added
            is_cmd5250=dict(type='bool', default=False),          
            asp_group=dict(type='str', default='*SYSBAS'),
            joblog=dict(type='bool', default=False),
            become_user=dict(type='str'),
            become_user_password=dict(type='str', no_log=True),
        ),
        supports_check_mode=True,
    )

    ibmi_util.log_info("version: " + __ibmi_module_version__, module._name)

    command = module.params['cmd'].strip()
    asp_group = module.params['asp_group'].strip().upper()
    joblog = module.params['joblog']
    become_user = module.params['become_user']
    become_user_password = module.params['become_user_password']

    startd = datetime.datetime.now()

    command_upper = command.upper()
### this line is removed
    # is_cmd5250 = False
    if command_upper.startswith('DSP'):
        is_cmd5250 = True
    if command_upper.startswith('QSYS/DSP'):
        is_cmd5250 = True
    if command_upper.startswith('WRK'):
        is_cmd5250 = True
    if command_upper.startswith('QSYS/WRK'):
        is_cmd5250 = True
    if 'OUTPUT(*)' in command_upper:
        is_cmd5250 = True
robgjertsen1 commented 8 months ago

That could be a potential option to allow the user to override the default behavior.