ansible command模块将返回值写入变量

ansible 中command模块支持 register参数将远程命令执行的输出结果存储在变量中,后续可以在when中对该变量进行检索确定下一步任务。

---
- name: cat /etc/redhat-release
  command: cat /etc/redhat-release
  register: output

- name: Your linux is CentOS
  command: echo "CentOS"
  when: output.stdout.find('CentOS') != -1

  

posted @ 2017-12-13 09:12  Peterer~王勇  阅读(2367)  评论(0编辑  收藏  举报