首页 > 解决方案 > 如何从 Ansible 的 Shell 脚本中搜索寄存器变量中的单词?

问题描述

我对 ansible 很陌生,我正在编写一组代码,其中 shell 命令的结果转到 Register 变量,在该变量中,我需要找到关键字“happy”。如果找到关键字,则执行另一个 shell 脚本。Shell 命令显然输出多个不同的值,看起来像一个字典,它不是一个直截了当的字符串,所以我如何在整个 shell 结果中找到一个单词。

我的尝试:

- name: execute first task
 shell: /tmp/somescript
 register: myResult
- name: another shell script
  shell: /tmp/anotherscript
  when: "happy" in myResult.

当输出对每个输出结果感到满意时,这将返回“条件为假”。

标签: shellansibleyaml

解决方案


推荐阅读