Assigning a unique random IP Address to each host

55 views
Skip to first unread message

pho...@startledphoenix.com

unread,
Apr 29, 2015, 4:58:58 PM4/29/15
to salt-...@googlegroups.com
To make OpenVPN tunnels between hosts a bit easier, I was wondering if there was a way to assign unique IP Addresses as grains for each minion.

For example:
minion1:
    localip:
        192.168.300.101
minion2:
    localip:
        192.168.300.103
minion3
    localip:
        192.168.300.110

They don't need to be contiguous, just as long as they are unique and within the range of a subnet (/24). I don't think there will ever be any way that I will manage to get to 100+ hosts, so a method to allocate from 192.168.300.100-192.168.300.200 would be fine by me.


Mohamed Lrhazi

unread,
Apr 29, 2015, 6:52:46 PM4/29/15
to salt-...@googlegroups.com
You don't care that it's contiguous, you probably also don't care that it is random. you only care that it is unique. You would need to remember what IPs you had assigned so far, so you can pick the next unique one...
I suppose you could do this in a Jina template... load current assigned IPs csv file, into a "by minion_id dictionary"... and add new entry for new minions?

StartledPhoenix

unread,
Apr 29, 2015, 7:13:15 PM4/29/15
to salt-...@googlegroups.com
Is there any documentation on how to import a CSV into salt, or will I have to do this through python?

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Florian Ermisch

unread,
Apr 29, 2015, 10:11:29 PM4/29/15
to salt-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Just use YAML/JSON/jinja to create a dictionary, don't bother with importing CSV for 2 values per minion. If you don't care about other minions seeing the assignment you can just list them in a key like [VPN:ips]:

vpn:
ips:
minion1: 192.0.2.101
minion2: 192.0.2.103
minion3: 192.0.2.110

Or use the pillar for the hostsfile-formula for hostnames like "minion1.vpn" and choose minion_id + ".vpn" for the IP in the openvpn-config.

For setting and especially retrieving a value on other minions you should take a look at the salt-mine.

And /please/, if you want an IPv4 address for documentation/examples use TEST-NET aka 192.0.2.0/24 [0] (or TEST-NET-2, TEST-NET-3) instead of something syntactically invalid…

Regards, Florian

[0] http://en.m.wikipedia.org/wiki/Reserved_IP_addresses
>>> 192.[0.2].101
>>> minion2:
>>> localip:
>>> 192.[0.2].103
>>> minion3
>>> localip:
>>> 192.[0.2].110
>>>
>>> They don't need to be contiguous, just as long as they are unique
>and
>>> within the range of a subnet (/24). I don't think there will ever be
>any
>>> way that I will manage to get to 100+ hosts, so a method to allocate
>from
>>> 192.[0.2].100-192.[0.2].200 would be fine by me.
>>>
-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQFTBAEBCAA9BQJVQY9DNhxGbG9yaWFuIEVybWlzY2ggPGZsb3JpYW4uZXJtaXNj
aEBhbHVtbmkudHUtYmVybGluLmRlPgAKCRAu8tzCHoBI/Zu/CACgMe7UTea/mXDW
/WFyKtDvjDiyk0EhmNhP3AI0ZHmNiYz5P1D6WYxeOxe3DIkaBoubet1gx6epbeIK
1B5V3hJA67prQ5q0ubSMNNmFZuB1gy1BhWEtd1ODtsMuLmlJg4FBNOjYVQrbLH98
c24rUuUSILY2JhVIQWMEfF6BtxLcJByScGXn65cGGZzFvkA1uHoTxVeKZecjzY99
MgpyFrJpxu+i5M87w6kh8LckeDXCQGHYM7LxoFa7Iiwh4pEWfru7HpkOxg6bdIJG
RVbwb2hq1NKBiYWlxCdPDb7ADX0aKSEtmBCQ1ymHjU2BE/QHu0tqlEX9qzSauaoQ
UVYp9Nee
=DmC3
-----END PGP SIGNATURE-----

Reply all
Reply to author
Forward
0 new messages