Use puppet to change the IP address on the nodes

puppetpuppetmaster

I have 3 CentOS nodes. Each of them has 2 IP addresses: 10.0.1.* (eth0) and 192.168.1.* (eth1). All of them have puppet installed and there is a master puppet server for managing configuration in these servers. All the servers interact with puppet server using the 10.0.1.* IPs.

My need is that I want to change the eth1 IP address on these servers. Can I have a generic config file that can be used to change the IP address on the 3 servers or should I have 3 different config files for the 3 servers?

Best Answer

Before writing your own code take a look at https://forge.puppetlabs.com. Because usually there is a module which totally covers all your needs.

In your case if I understand your task correctly it's https://forge.puppetlabs.com/example42/network

If you still want to do that manually you should either use simple template substitution as was mentioned already or augeas which I think a better idea.

For example to configure vmbr0 interface you need to add something like this for Debian:

augeas{ "vmbr0_interface" :
        context => "/files/etc/network/interfaces",
        changes => [
                "set auto[child::1 = 'vmbr0']/1 vmbr0",
                "set iface[. = 'vmbr0'] vmbr0",
                "set iface[. = 'vmbr0']/family inet",
                "set iface[. = 'vmbr0']/method static",
                "set iface[. = 'vmbr0']/address 192.168.11.1",
                "set iface[. = 'vmbr0']/netmask 255.255.255.0",
                "set iface[. = 'vmbr0']/bridge_ports none",
                "set iface[. = 'vmbr0']/bridge_stp off",
                "set iface[. = 'vmbr0']/bridge_fd 0"
        ]
}

And for CentOS:

        augeas { "eth1":
            context => "/files/etc/sysconfig/network-scripts/ifcfg-eth1",
            changes => [
                "set DEVICE eth1",
                "set BOOTPROTO none",
                "set ONBOOT yes",
                "set NETMASK 255.255.255.0",
                "set IPADDR 10.12.0.10",
            ],
        }

Also follow this link http://projects.puppetlabs.com/projects/1/wiki/Network_Interface_Templates_Patterns. It has some nice thoughts about network configuration.

Related Topic