Hi,
Jeff had helped me figure this out in IRC last week... but I'm not understanding it like I thought I did...
First off... just working with my apache config files... was trying to get the box to auto insert its IP address in the NameVirtualHost settings in the configs automatically
We had come up with a state that looks like this:
/etc/nginx/sites-available/website:
file.managed:
- source: salt://roles/loadbalancer/files/website.conf
- user: root
- group: root
- mode: 644
- template: jinja
- context:
vhost_ip: {{ salt['network.interfaces']()['eth0']['ipaddr'] }}
This works great for the primary IP on the interface. Now, since I have multiple SSL Certs... I have the need for multiple IP's on the box.
I have aliases on eth0 for the other IP's.
From the Salt master, I can run the network.interfaces module, which returns this:
'hwaddr': '00:50:56:92:27:a9',
'ipaddr': '172.22.10.100',
'ipaddr6': 'fe80::250:56ff:fe92:27a9',
'netmask': '255.255.255.0',
'netmask6': '64',
'secondary': [{'broadcast': '172.22.10.255',
'ipaddr': '172.22.10.101',
'netmask': '255.255.255.0',
'type': 'inet'},
{'broadcast': '172.22.10.255',
'ipaddr': '172.22.10.102',
'netmask': '255.255.255.0',
'type': 'inet'}],
'up': True},
'lo': {'broadcast': None,
'hwaddr': '00:00:00:00:00:00',
'ipaddr': '127.0.0.1',
'ipaddr6': '::1',
'netmask': '255.0.0.0',
'netmask6': '128',
'up': True}}}
The secondary IP's are what I want...
I can make sure and define that eth0:1 will always be website x, and eth0:2 will be website y...
who do I get the state file to pull those secondary IP's?
salt['network.interfaces']()['eth0']['secondary'][0]['ipaddr']
doesn't seem to work... and I can't figure out what my syntax should be on the cli...
Running in debug from the client looks like:
[INFO ] Executing command ip addr show in directory /root
[DEBUG ] output: 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:92:27:a9 brd ff:ff:ff:ff:ff:ff
inet6 fe80::250:56ff:fe92:27a9/64 scope link
valid_lft forever preferred_lft forever
Too many functions declared in state "file" in sls roles.loadbalancer
Too many functions declared in state "file" in sls roles.loadbalancer
Too many functions declared in state "file" in sls roles.loadbalancer
to which I tried using: salt['network.interfaces']()['eth0']['secondary']['eth0:1']['ipaddr']
Which results in:
[INFO ] Executing command ip addr show in directory /root
[DEBUG ] output: 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:92:27:a9 brd ff:ff:ff:ff:ff:ff
inet6 fe80::250:56ff:fe92:27a9/64 scope link
valid_lft forever preferred_lft forever
Rendering SLS roles.loadbalancer failed, render error:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/utils/templates.py", line 91, in jinja
data = template.render(**passthrough)
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "/var/cache/salt/files/base/roles/loadbalancer/init.sls", line 28, in top-level template code
vhost_ip: {{ salt['network.interfaces']()['eth0']['secondary']['eth0:1']['ipaddr'] }}
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 353, in getitem
UndefinedError: 'list object' has no attribute 'eth0:1'
Thoughts?
If you think I should approach this differently I'm all ears for that too.
-Mitch