我想使用Ansible任务来检查已注册的可变符中是否存在字符串。
我正在尝试使用一个任务来使用ps
来获取进程的命令行参数,并将其注册为command_line
。
然后,我想执行几个任务,这些任务只是检查command_line
中是否存在字符串。
我尝试过:
- name: Get command line args
raw: ps aux | grep "binary" | grep -v grep
register: command_line
changed_when: False
- name: Check --hello-world flag passed
failed_when: "'--hello-world' not in command_line.stdout"
这不起作用,因为第二个任务中没有任何操作。会引发错误。
注意:服务器上没有Python,因此我无法使用大多数Ansible动作。
答案 0 :(得分:0)
尝试以下条件
when: command_line.stdout is not search('--hello-world')