【发布时间】:2019-12-31 17:28:13
【问题描述】:
我想列出在上述主机中运行的 java 进程。但是我没有得到想要的 o/p
已经创建了一个 ansible-playbook 文件来读取 shell 命令。
name: 'Check the running java processes'
hosts: all
tasks:
- name: 'check running processes'
shell: ps -ef | grep -i java```
output: PLAY [Check the running java processes] ****************************************
TASK [setup] *******************************************************************
ok: [target1]
ok: [target2]
TASK [check running processes] *************************************************
changed: [target1]
changed: [target2]
PLAY RECAP *********************************************************************
target1 : ok=2 changed=1 unreachable=0 failed=0
target2 : ok=2 changed=1 unreachable=0 failed=0
However, it's not listing the processes.
【问题讨论】:
-
我现在无法测试它,但也许命令会比 shell 更好。我的想法是 shell 将有自己的标准输出与 ansible 登录分开
-
@Terry:
command模块会因为 OP 命令中的管道而引发错误 ->The command(s) will not be processed through the shell, so variables like $HOME and operations like "<", ">", "|", ";" and "&" will not work. Use the shell module if you need these features.。此外,即使使用更简单的命令,它也不会改变当前的问题。
标签: ansible