0

when manually ran db2 command on the server works. But when executing using ansible which switches to the user but fails to run the db2 command. I am stuck on this issue for the whole day. Any suggestions would be greatly helpful.

task item:

- name: Connect to tsmdb1 database
  become: true
  become_user: user
  shell: 'db2 connect to tsmdb1'
  args:
    chdir: /opt/tivoli/tsm/tsmmp/cfg
  register:  Connect_tsmdb1
  ignore_errors: true

Output:

fatal: [user]: FAILED! => {
    "changed": true,
    "cmd": "db2 connect to tsmdb1",
    "delta": "0:00:00.142899",
    "end": "2019-05-27 17:00:57.885281",
    "invocation": {
        "module_args": {
            "_raw_params": "db2 connect to tsmdb1",
            "_uses_shell": true,
            "argv": null,
            "chdir": "/opt/tivoli/tsm/tsmmp/cfg",
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": true
        }
    },
    "msg": "non-zero return code",
    "rc": 127,
    "start": "2019-05-27 17:00:57.742382",
    "stderr": "/bin/sh: db2: command not found",
    "stderr_lines": [
        "/bin/sh: db2: command not found"
    ],
    "stdout": "",
    "stdout_lines": []

1 Answer 1

0
"stderr": "/bin/sh: db2: command not found",

the db2 command is not found in the regular $PATH. Your user probably has something in one of the profile files that makes sure you can find the db2 executable.

You have two options:

If you just need the path and no other variables set find out where the executable is by logging on and running type db2 Then use the full path in your ansible shell:

shell: '/path/to/db2 connect to tsmdb1'

Or you might need other environment variables in whatever file is providing the db2 info. Find out which it is (suspects are /etc/profile , ~/.bashrc , ...) and source it:

shell: '. /home/user/.bashrc && db2 connect to tsmdb1'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .