Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Ansible中的Shell脚本中搜索寄存器变量中的单词?_Shell_Ansible_Yaml - Fatal编程技术网

如何从Ansible中的Shell脚本中搜索寄存器变量中的单词?

如何从Ansible中的Shell脚本中搜索寄存器变量中的单词?,shell,ansible,yaml,Shell,Ansible,Yaml,我对ansible非常陌生,我正在编写一组代码,其中shell命令的结果将传递给寄存器变量,在该变量中,我需要找到关键字“happy”。如果找到关键字,则执行另一个shell脚本。Shell命令显然输出了多个不同的值,看起来像一个字典,它不是一个直接的字符串,所以如何在整个Shell结果中找到一个单词 我的尝试: - name: execute first task shell: /tmp/somescript register: myResult - name: another shell

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

我的尝试:

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

当输出结果中确实包含happy时,返回“condition was false”。

尝试
当myResult.stdout中的“'happy'”
要添加到@VladimirBotka advice中,您应该调试已注册var的内容,以了解其结构和内容。您还应该阅读
shell
模块文档,其中记录了所有返回的字段。添加stdout有效:D@Zeitounator我也进行了调试,stdout缩小了结果范围。非常感谢大家:)。