1

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?

Krishna Kumar R
  • 193
  • 1
  • 2
  • 6
  • Both will work but the better way is to use a template and a parametrized class. See https://docs.puppetlabs.com/learning/modules2.html – Mark Wagner Oct 24 '14 at 17:57

1 Answers1

2

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.

Glueon
  • 3,664
  • 2
  • 24
  • 32
  • Note that CentOS doesn't use `/etc/network/interfaces`. But he should be able to figure that himself. – faker Oct 24 '14 at 18:43
  • I need to dynamically assign IPs on the nodes? Is that possible? Do you have an example for that? – Krishna Kumar R Oct 24 '14 at 18:44
  • What is "dynamic"? If you specify any IP address for any node using network module is that dynamic? Because I am thinking about DHCP right now. But then how is puppet involved here? – Glueon Oct 24 '14 at 18:52
  • My bad! On the above snippet, will "set iface[. = 'vmbr0']/method dhcp" work? – Krishna Kumar R Oct 24 '14 at 19:01
  • Yes and remove unnecessary fields. But be aware, this is snippet is for debian. You should correct paths and contents as well to match CentOS. – Glueon Oct 24 '14 at 20:12
  • Added CentOS variant too. – Glueon Oct 24 '14 at 20:20
  • 1
    +1 to the `example42/network` module. The `augeas` type is generally not the friendliest beast. It can (and probably should) usually be avoided. – Felix Frank Oct 25 '14 at 21:20