我有3个CentOS节点。 它们每个都有两个IP地址:10.0.1。*(eth0)和192.168.1。*(eth1)。 他们都安装了puppet,并且有一个master puppet服务器来pipe理这些服务器的configuration。 所有服务器都使用10.0.1。* IP与puppet服务器进行交互。
我的需要是我想改变这些服务器上的eth1 IP地址。 我可以有一个通用的configuration文件,可以用来更改3个服务器的IP地址,或者我应该有3个不同的configuration文件的3个服务器?
在编写自己的代码之前,请查看https://forge.puppetlabs.com 。 因为通常有一个模块可以完全满足您的所有需求。
在你的情况下,如果我正确理解你的任务是https://forge.puppetlabs.com/example42/network
如果你仍然想手动这样做,你应该使用简单的模板replace,如已经提到的或者augeas
,我认为这是一个更好的主意。
例如,要configurationvmbr0
接口,您需要为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" ] }
而对于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", ], }
也请按照此链接http://projects.puppetlabs.com/projects/1/wiki/Network_Interface_Templates_Patterns 。 对networkingconfiguration有一些好的想法。