本文主要是介绍Ansible -IF/then/when-Conditionals,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
IF/then/when-Conditionals
Ansible uses expressions and built-ins with when ,changed_when , and failed_when so you can describe these things to Ansible with as much precision as possible.
Jinja2 allows the definition of literals like strings ( “string” ), integers ( 42 ), floats ( 42.33 ), lists ( [1,2, 3] ), tuples (like lists, but can’t be modified) dictionaries ( {key: value, key2: value2} ), and booleans ( true or false ).
Jinja2 also allows basic math operations, like addition, subtraction, multiplication and division, and comparisons( == forequality, != forinequality, >= forgreaterthanorequalto,etc.).Logicaloperatorsare and , or , and not , and you can group expressions by placing them within parenthesis.
---
- hosts: appservertasks:- name: Do something only for version 4 of the software.command: "hostname"when: software_version.split('.')[0] == '4'
register
- name: Create a register to represent the status if the /dev/sda6 exsitedshell: df -h | grep sda6register: dev_sda6_resultignore_errors: Truetags: docker- name: Copy docker-thinpool.sh to all hostscopy: src=docker-thinpool.sh dest=/usr/bin/docker-thinpool mode=0755when: dev_sda6_result | succeededtags: docker- yum: name=mysql-server state=presentwhen: is_db_server
这篇关于Ansible -IF/then/when-Conditionals的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!