Wednesday, November 21, 2012
How to template eth0 ip address with Saltstack Jinja
You can test the output of salt network interfaces with
# salt 'some-machine' network.interfaces
Here is the Salt state file, we will write /etc/haproxy/haproxy.cfg with the context of the eth0 ip address
Below is the content of haproxy.sls
#
# Write /etc/haproxy/haproxy.cfg
#
/etc/haproxy/haproxy.cfg:
file.managed:
- source: salt://files/etc/haproxy/haproxy.cfg
- user: root
- group: root
- mode: 640
- template: jinja
- context:
ip: {{ salt['network.interfaces']()['eth0']['inet'][0]['address'] }}
file referenced in source: salt:// above content of files/etc/haproxy/haproxy.cfg
the important part is to write the variable in thise case ip as {{ variable }}
listen stats {{ ip }}:10000
Subscribe to:
Post Comments (Atom)
Thanks for this post, helped me out
ReplyDeleteThanks,
ReplyDeleteIs this best way ?
http://intothesaltmine.org/index5.html
{{ salt['network.ip_addrs']('eth0')[0] }}
salt 2014.1.0:
ReplyDelete{{ grains['ip_interfaces']['eth0'][0] }}