Linux 使用ansible运行db2relocatedb

Linux 使用ansible运行db2relocatedb,linux,ansible,db2,Linux,Ansible,Db2,我有一本ansible剧本: --- - hosts: all gather_facts: False become: yes become_user: myins become_method: sudo tasks: - name: test someting command: "cd /db2/myins" - name: relocate it command: "db2relocatedb -f /

我有一本ansible剧本:

 ---
 - hosts: all
   gather_facts: False
   become: yes
   become_user: myins
   become_method: sudo

   tasks:

     - name: test someting
       command: "cd /db2/myins"

     - name: relocate it 
       command: "db2relocatedb -f /db2/myins/relocate.cfg"

 ...
如果我自己运行这个命令,它就会工作,如果我使用cat/db2/myins/relocate.cfg而不是db2relocatedb-f,它也会工作

如果我这样运行,我会得到:

 The full traceback is:
 WARNING: The below traceback may *not* be related to the actual failure.
 File "/tmp/ansible_command_payload_HGHkvR/ansible_command_payload.zip/ansible/module_utils/basic.py", line 2561, in run_command
cmd = subprocess.Popen(args, **kwargs)
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception

fatal: [mounttest]: FAILED! => {
"changed": false,
"cmd": "db2relocatedb -f /db2/myins/relocate.cfg",
"invocation": {
    "module_args": {
        "_raw_params": "db2relocatedb -f /db2/myins/relocate.cfg",
        "_uses_shell": false,
        "argv": null,
        "chdir": null,
        "creates": null,
        "executable": null,
        "removes": null,
        "stdin": null,
        "stdin_add_newline": true,
        "strip_empty_ends": true,
        "warn": true
    }
},
"msg": "[Errno 2] No such file or directory",
"rc": 2
 }
为什么我可以对文件进行cat,但不能使用它

谢谢,
Arengin

问题出在relocate.cfg内,检查所有路径,确保它们完全合格,确保某个地方没有转义字符

mytestuser,但我使用“变成”来更改为正确的用户我有centOS并运行ansible2.8.0命令在路径上,因为我可以在登录到机器的任何地方运行它。我现在更改了yml,将文件复制到目录,然后使用它。它确实复制了它,然后说msg:[Errno 2]没有这样的文件或目录,rc:2您的评论说db2relocatedb作为mytestuser在shell上运行正常,但您的问题已经变成了_user:myins。可能是ansible没有运行db2relocatedb可能依赖的shell启动脚本,ansible可能使用不同的$PWD。您可以使用-vvv选项运行ansible,以提供位置的更多详细信息。确定。。由于某些原因,该命令需要一个cd文件夹&db2relocate。。。以前连一张cd都不够,答案不准确。如果你认为问题的根源是在一个没有被问题预览过的文件中,请在评论中询问更多信息,然后明确指出。