基于结果的标准输出的 Ansible 条件? [英] Ansible conditional based on stdout of result?

查看:16
本文介绍了基于结果的标准输出的 Ansible 条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用基于register:result的标准输出的when语句?如果存在标准输出,我希望运行 somecommand 如果不存在标准输出,我希望运行 someothercommand.

How do I use the when statement based on the standard output of register: result? If standard output exists I want somecommand to run if no standard output exists I want someothercommand to run.

- hosts: myhosts
  tasks:
  - name: echo hello
    command: echo hello
    register: result
  - command: somecommand {{ result.stdout }}
    when: result|success
  - command: someothercommand
    when: result|failed

推荐答案

尝试检查它是否等于空字符串?

Try checking to see it if equals a blank string or not?

- hosts: myhosts
  tasks:
  - name: echo hello
    command: echo hello
    register: result
  - command: somecommand {{ result.stdout }}
    when: result.stdout != ""
  - command: someothercommand
    when: result.stdout == ""

这篇关于基于结果的标准输出的 Ansible 条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆