Think before you speak, read before you think.

ansible jinja2模板使用

by

in

在j2中可以很方便的使用 ansible setup 模块中的变量

如以下是一个bind的配置文件

  {% if ansible_bond0.ipv4.address %}
  bind {{ ansible_bond0.ipv4.address }}
  {% elif ansible_eth0.ipv4.address %}
  bind {{ ansible_eth0.ipv4.address }}
  {% else %}
  bind 0.0.0.0
  {% endif %}

以下是一个snmp磁盘分区的设定

{% for i in ansible_mounts %}
{% if i['mount']  != '/boot' %}
disk {{ i['mount'] }} 10% 
{% endif %}
{% endfor %}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *