Ansible conditional based on stdout of result?

前端 未结 2 1889
陌清茗
陌清茗 2020-12-29 04:10

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 so

2条回答
  •  孤城傲影
    2020-12-29 04:55

    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 == ""
    

提交回复
热议问题