Re: [Puppet Users] Static IP assignment

826 views
Skip to first unread message

Matthew Burgess

unread,
Oct 17, 2012, 10:36:37 AM10/17/12
to puppet...@googlegroups.com
On Wed, Oct 17, 2012 at 3:13 PM, GordonJB <g.bon...@gmail.com> wrote:
> I have a server which we're running a lot of VM's on, including a Puppet
> master and various nodes under puppet management. When we add new VM's with
> VSphere, the new nodes have dynamic IP's.
>
> What we're looking to do is have each VM have a static IP and have these
> automatically assigned from a pool of addresses. I am looking in to Puppet
> to do this (so i.e. when we add a new puppet node, it is given a static IP
> address). Is this something that's possible? If so, how would I go about it?
> I looked into Foreman, but honestly I could never quite figure out if it was
> what I needed, or get it set up on a server.

You could use Foreman, as it can manage DHCP for you, but if you're not
planning to use any of its other features, its probably a bit of an overkill.

All you need is a DHCP server, where you'd configure your range of static
IP addresses that you want your VMs to sit in, and presumably a list of
MAC address to IP address mappings.

There are a number of modules on the puppet forge
(http://forge.puppetlabs.com/) concerning DHCP that you could either
make use of directly, or use as inspiration for your own.

Regards,

Matt.
Message has been deleted

GordonJB

unread,
Oct 17, 2012, 10:51:17 AM10/17/12
to puppet...@googlegroups.com
So I take it that when the new VM announces itself to the network, it will go off to the DHCP server and pick a static IP if there is one defined already for it's MAC address in a config file somewhere? Is there a way to have a MAC address/IP pairing generated if one does not exist? 

Thanks,
Gordon

Matthew Burgess

unread,
Oct 17, 2012, 11:02:46 AM10/17/12
to puppet...@googlegroups.com
On Wed, Oct 17, 2012 at 3:49 PM, GordonJB <g.bon...@gmail.com> wrote:
> So I take it that when the new VM announces itself to the network, it will
> go off to the DHCP server and pick a static IP if there is one defined
> already for it's MAC address in a config file somewhere?

Yes, that's correct. You can also set up a generic pool of addresses
that a VM may get one from if you don't know its MAC address, but then
you're not guaranteed to get the same IP address every time.

The problem I encountered with VMWare VMs was that the MAC address
wasn't generated until the VM was first powered on, so configuring
DHCP ahead of time wasn't possible. As we didn't have any automated
provisioning set up, the process was to do an initial boot and
interrupt the boot process fairly quickly and power the VM off. Then
I'd grab the MAC address from VSphere and pop it into the DHCP
server's config.

> Is there a way to have a MAC address/IP pairing generated if one does not exist?

I think the approach I'd take with this is to have a fairly small pool
of addresses used for temporary IPs while a box is being provisioned.
Once the box is up, you could have another puppet module that would
figure out, using some other policy (potentially as simple as doing a
DNS lookup on your VM's hostname), what the IP address of the box
should be, find the MAC address of the NIC (exposed by facter), then
put that in to the DHCP server's config. Automated provisioning
solutions such as Foreman or Razor
(http://puppetlabs.com/blog/puppet-razor-module/) may have
better/other ways of doing it, but that would be my initial approach.
That Razor page also links to Puppetlabs' own DHCP module
(https://github.com/puppetlabs/puppetlabs-dhcp), so I'd be prone to
try that for your DHCP config needs first, before looking at modules
on the Forge.

Regards,

Matt.

GordonJB

unread,
Oct 17, 2012, 11:19:29 AM10/17/12
to puppet...@googlegroups.com
OK, that all makes sense, thanks for the help!

Aaron Grewell

unread,
Oct 17, 2012, 11:36:47 AM10/17/12
to puppet...@googlegroups.com
I'm currently experimenting with an option added in vSphere 5 that has
promise: assuming your VM Template has VMware Tools preinstalled you
can use the Perl API to run programs directly in the resulting VM.
Assuming you have API access (vSphere or commercially licensed ESXi
have this, the free version doesn't) you can address the VM by name
once it's started and run whatever programs you like. No need for
network, etc.

See:
http://www.virtuallyghetto.com/2011/07/automating-new-integrated-vixguest.html
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/puppet-users/-/UJQuzY-oj_kJ.
>
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.

Ohad Levy

unread,
Oct 17, 2012, 5:18:54 PM10/17/12
to puppet...@googlegroups.com
On Wed, Oct 17, 2012 at 5:02 PM, Matthew Burgess <matthew....@gmail.com> wrote:
On Wed, Oct 17, 2012 at 3:49 PM, GordonJB <g.bon...@gmail.com> wrote:
> So I take it that when the new VM announces itself to the network, it will
> go off to the DHCP server and pick a static IP if there is one defined
> already for it's MAC address in a config file somewhere?

Yes, that's correct.  You can also set up a generic pool of addresses
that a VM may get one from if you don't know its MAC address, but then
you're not guaranteed to get the same IP address every time.

The problem I encountered with VMWare VMs was that the MAC address
wasn't generated until the VM was first powered on, so configuring
DHCP ahead of time wasn't possible.  As we didn't have any automated
provisioning set up, the process was to do an initial boot and
interrupt the boot process fairly quickly and power the VM off.  Then
I'd grab the MAC address from VSphere and pop it into the DHCP
server's config.

just FYI - Foreman creates the vm, then fetch the vm new mac, create a dhcp entry with that mac, and at the end powers on the vm.

Ohad 

> Is there a way to have a MAC address/IP pairing generated if one does not exist?

I think the approach I'd take with this is to have a fairly small pool
of addresses used for temporary IPs while a box is being provisioned.
Once the box is up, you could have another puppet module that would
figure out, using some other policy (potentially as simple as doing a
DNS lookup on your VM's hostname), what the IP address of the box
should be, find the MAC address of the NIC (exposed by facter), then
put that in to the DHCP server's config.  Automated provisioning
solutions such as Foreman or Razor
(http://puppetlabs.com/blog/puppet-razor-module/) may have
better/other ways of doing it, but that would be my initial approach.
That Razor page also links to Puppetlabs' own DHCP module
(https://github.com/puppetlabs/puppetlabs-dhcp), so I'd be prone to
try that for your DHCP config needs first, before looking at modules
on the Forge.

Regards,

Matt.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
Reply all
Reply to author
Forward
0 new messages