ansible-for-i icon indicating copy to clipboard operation
ansible-for-i copied to clipboard

Different stdout for ibmi_cl_command for CHKPRDOPT *OPSYS

Open syahrul-aiman opened this issue 1 year ago • 5 comments

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 avatar Oct 27 '23 13:10 syahrul-aiman

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:

  • DSP
  • QSYS/DSP
  • WRK
  • QSYS/WRK

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 avatar Oct 28 '23 00:10 syahrul-aiman

Another option is to allow explicit setting of is_cmd5250 to true

syahrul-aiman avatar Oct 28 '23 00:10 syahrul-aiman

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.

robgjertsen1 avatar Nov 07 '23 17:11 robgjertsen1

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

syahrul-aiman avatar Nov 09 '23 00:11 syahrul-aiman

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

robgjertsen1 avatar Nov 14 '23 21:11 robgjertsen1