把表达式 当成变量存储 ,only_if 动作 去解析 执行
ansible 中变量 可以 组合
- role: foo
param1: '{{ foo }}'
param2: '{{ some_var1 + "/" + some_var2 }}'
when: ansible_os_family == 'RedHat'
SHA e6406fa5
实现方式
这种神奇的方式,在ansible中是这样实现的
- 调用double_template 对变量进行两层替换
- 对替换的结果 执行eval
runner.py v0.0.2 中
#host file
[staging]
staging.myproject.com nickname=staging vm=0 branch=develop
#playbook
vars:
favcolor: “red”
dog: “fido”
cat: “whiskers”
ssn: 8675309
name: Upload SSH key.
copy: src=key dest=/home/.ssh/id_rsa mode=0600
only_if: “$vm == 0”name: “do this if my favcolor is blue, and my dog is named fido”
action: shell /bin/false
when_string: $favcolor == ‘blue’ and $dog == ‘fido’