ansible通过when判断变量

通过when判断变量示例:

( “{{变量}}” == ‘1’ )

---
- hosts: tomcat
  vars:
        tomca: 1
  tasks:
      - name: "nod1安装httpd"
        yum: name=httpd state=installed
        when: tomca == 1    #当变量等于co1时执行 ,不能加单引号,双引号
      - name: "nod2安装mysql"
        yum: name=mariadb,mariadb-server state=removed
        when: tomca == 2   #当变量等于co2时执行

效果
在这里插入图片描述
成功
在这里插入图片描述

发布了139 篇原创文章 · 获赞 240 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/a13568hki/article/details/103877362