语法:
{% for i in range(1,10)%} server 172.16.1.{{i}}; {% endfor %} #判断 {% if ansible_fqdn == "web01" %} echo 123 {% elif ansible_fqdn == "web02" %} echo 456 {% else %} echo 789 {% endif %}
template模块
- name: Configure nginx Server template: src: /etc/conf.j2 dest: /etc/test.conf
jinjia2
# jinjia2里面可以直接使用Ansible的魔法变量 hostvars groups inventory_hostname group_names
{% for host in hosts %} {{ host }} {% endfor %}