Ansible -IFthenwhen-Conditionals

xiaoxiao2021-03-01  5

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: appserver tasks: - 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 exsited shell: df -h | grep sda6 register: dev_sda6_result ignore_errors: True tags: docker - name: Copy docker-thinpool.sh to all hosts copy: src=docker-thinpool.sh dest=/usr/bin/docker-thinpool mode=0755 when: dev_sda6_result | succeeded tags: docker - yum: name=mysql-server state=present when: is_db_server
转载请注明原文地址: https://www.6miu.com/read-3200296.html

最新回复(0)