jinja模版的使用方法:
1、file状态使用template参数
- template:jinja
2、模版文件里面变量使用{{名称}},例如{{PORT}}
变量使用Grains:{{ grains[‘fqdn_ip4‘] }}
变量使用执行模块:{{ salt[‘network.hw_addr‘](‘eth0‘) }}
变量使用Pillar:{{ pillar[‘apache‘][‘PORT‘] }}
3、变量列表
- defaults: PORT:8080
举例说明
[root@linux-node1 base]# cd /srv/salt/base/
[root@linux-node1 base]# vim dns.sls
/etc/resolv.conf:
file.managed:
- source: salt://files/resolv.conf
- user: root
- group: root
- mode: 644
- template: jinja
- defaults:
DNS_SERVER: 10.0.0.2
[root@linux-node1 base]# vim files/resolv.conf
###hehe
nameserver {{ DNS_SERVER }}
[root@linux-node1 base]# salt ‘*‘ state.highstate本文出自 “万越天的架构师之路” 博客,请务必保留此出处http://wanyuetian.blog.51cto.com/3984643/1717289
原文地址:http://wanyuetian.blog.51cto.com/3984643/1717289