Ansible: Store command's stdout in new variable?

前端 未结 6 648
暗喜
暗喜 2020-12-22 22:35

Inside my playbook I\'d like to create a variable holding the output of an external command. Afterwards I want to make use of that variable in a couple of templates.

6条回答
  •  轮回少年
    2020-12-22 23:12

    In case than you want to store a complex command to compare text result, for example to compare the version of OS, maybe this can help you:

    tasks:
           - shell: echo $(cat /etc/issue | awk {'print $7'})
             register: echo_content
    
           - shell: echo "It works"
             when: echo_content.stdout == "12"
             register: out
           - debug: var=out.stdout_lines
    

提交回复
热议问题