Am trying to create a template where it will retrieve the IP address of consul servers as DNS using mine.get
. On command line it seems to work fine, but when used in the template context its not returning anything
Here is my setup
In /srv/pillar I added mines.sls
and modified top.sls
as following
mines.sls
mine_functions:
network.ip_addrs: []
top.sls
base:
'*':
- mines
After refreshing pillars and using mine.send
and mine.update
, I could query from saltmaster server the IP addresses for consul
sudo salt 'redis*' mine.get 'consul*' network.ip_addrs
redis-001-stage.c.project-gce.internal:
----------
consul-001-adm.c.project-gce.internal:
- 192.16.0.1
consul-002-adm.c.project-gce.internal:
- 192.16.0.2
I tried to apply the same principle in a state file using templates
# Resolver Configuration
resolv-file:
file.managed:
- name: /etc/resolv.conf
- user: root
- group: root
- mode: '0644'
- source: salt://resolver/files/resolv.conf
- template: jinja
- defaults:
nameservers: {{ salt['mine.get']('*', 'network.ip_addrs', 'eth1').items() }}
and in resolve.conf
{%- for nameserver in nameservers %}
nameserver {{ nameserver }}
{%- endfor %}
but the nameservers always coming up empty, can someone advise please?