【发布时间】:2019-05-27 18:48:49
【问题描述】:
我正在使用 ansible 连接到远程 Linux 机器。我想执行一个特定于应用程序的命令,该命令将为我提供应用程序版本。但在此之前,必须执行一个 shell 脚本,该脚本将为上述命令执行设置环境。
目前,每个任务似乎都在单独的 shell 中执行
我想在执行/ds1/home/has9e/CS9/psconfig.sh后执行psadmin -v:
- command: "{{ item }}"
args:
chdir: "/ds1/home/has9e/CS9/"
with_items:
- "./psconfig.sh"
- "psadmin -v"
register: ptversion
ignore_errors: true
错误是:
failed: [slc13rog] (item=./psconfig.sh) => {
"changed": false,
"cmd": "./psconfig.sh",
"invocation": {
"module_args": {
"_raw_params": "./psconfig.sh",
"_uses_shell": false,
"argv": null,
"chdir": "/ds1/home/has9e/CS9/",
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "./psconfig.sh",
"msg": "[Errno 8] Exec format error",
"rc": 8
}
【问题讨论】:
-
你能把你的代码贴在这里吗?您是否尝试过剧本中的“shell”模块?您的要求很明确,但没有您到目前为止所做的事情,它有点完成帮助
-
请在下面找到我的任务 - 命令:"{{ item }}" args: chdir: "/ds1/home/has9e/CS9/" with_items: - "./psconfig.sh" - " psadmin -v" 注册:ptversion ignore_errors: true
-
尝试使用 shell 而不是命令模块。如下所示 - shell: "{{ item }}" args: chdir: "/ds1/home/has9e/CS9/" with_items: - "./psconfig. sh" - "psadmin -v" 注册:ptversion ignore_errors: true