Hi, I am trying to set up puppet for creating configuration files for automatic installation. I have a node which runs both puppet master and dhcp server. On this node I wanna create configuration file for dhcpd which will contain static ip address definition for each host. Like this : ... host node1 { hardware ethernet 08:00:27:ed:8f:ea; fixed-address 192.168.2.1; } host node2 { hardware ethernet 08:00:27:df:b4:0c; fixed-address 192.168.2.2; } host node3 { hardware ethernet 78:e7:d1:24:5c:10; fixed-address 192.168.2.3; } ... My configuration: /etc/puppet/manifests/site.pp: import "nodes/puppet.pp" /etc/puppet/manifests/nodes/puppet.pp: import "/etc/puppet/manifests/roles/puppetserver.pp" node ''puppet'' inherits puppetserver { } #node puppet /etc/puppet/manifests/roles/puppetserver.pp: import "/etc/puppet/manifests/roles/basenode.pp" node ''puppetserver'' inherits basenode { preseed { "node1": mac1 => "44-1e-a1-39-05-a0", mac2 => "44:1e:a1:39:05:a0", ip => "192.168.2.1", netmask => "255.255.0.0", "node2": mac1 => "78-e7-d1-24-5f-d0", mac2 => "78:e7:d1:24:5f:d0", ip => "192.168.2.2", netmask => "255.255.0.0", "node3": mac1 => "78-e7-d1-24-5c-10", mac2 => "78:e7:d1:24:5c:10", ip => "192.168.2.3", netmask => "255.255.0.0", } #preseed include dhcpd } # node This is puppet module for preseed and dhcpd. /etc/puppet/modules/preseed/manifests/init.pp: class dhcpd { package { "isc-dhcp-server": ensure => installed, } #package service { "isc-dhcp-server": ensure => $ensure, enable => true, require => Package["isc-dhcp-server"], } #service file { "/etc/default/isc-dhcp-server": ensure => present, path => "/etc/default/isc-dhcp-server", mode => 644, content => template("preseed/isc-dhcp-server.erb"), require => Package["isc-dhcp-server"], notify => Service["isc-dhcp-server"], } #file } #class define preseed ($mac1 = dflt, $mac2 = undef, $ip, $netmask) { include dhcpd file { "/var/www/preseed_$name.cfg": ensure => present, mode => 644, content => template("preseed/preseed_web.cfg.erb"), } #file file { "/var/lib/tftpboot/pxelinux.cfg/01-$mac1": ensure => present, mode => 644, content => template("preseed/pxe-config.erb"), require => File["/var/www/preseed_$name.cfg"], } #file file { "/etc/dhcp/dhcpd.conf-$name": ensure => present, path => "/etc/dhcp/dhcpd.conf", mode => 644, content => template("preseed/dhcpd.conf.erb"), require => Package["isc-dhcp-server"], notify => Service["isc-dhcp-server"], } #file } #define dhcpd.conf.erb: ... <% name.each do |val| -%> host <%= val %> { hardware ethernet <%= mac2 %>; fixed-address <%= ip %>; } <% end -%> When I try to apply this configuration, I receive this message: root@puppet:/# puppet agent --test --server=puppet.domain.com info: Caching catalog for puppet.domain.com err: Could not run Puppet configuration client: Cannot alias File[/etc/ dhcp/dhcpd.conf-node1] to ["/etc/dhcp/dhcpd.conf"]; resource ["File", ["/etc/dhcp/dhcpd.conf"]] already exists What is the best way to create a configuration that applies only to one node, but have to contain different parameters for each node. Thanks. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Apr 26, 6:51 am, Jiří Červenka <jiricerven...@gmail.com> wrote:> Hi, > I am trying to set up puppet for creating configuration files for > automatic installation. I have a node which runs both puppet master > and dhcp server. On this node I wanna create configuration file for > dhcpd which will contain static ip address definition for each host. > Like this : > > ... > host node1 { hardware ethernet 08:00:27:ed:8f:ea; fixed-address > 192.168.2.1; } > host node2 { hardware ethernet 08:00:27:df:b4:0c; fixed-address > 192.168.2.2; } > host node3 { hardware ethernet 78:e7:d1:24:5c:10; fixed-address > 192.168.2.3; } > ... > > My configuration: > > /etc/puppet/manifests/site.pp: > import "nodes/puppet.pp" > > /etc/puppet/manifests/nodes/puppet.pp: > import "/etc/puppet/manifests/roles/puppetserver.pp" > > node ''puppet'' inherits puppetserver { > } #node puppet > > /etc/puppet/manifests/roles/puppetserver.pp: > import "/etc/puppet/manifests/roles/basenode.pp" > node ''puppetserver'' inherits basenode { > preseed { > "node1": > mac1 => "44-1e-a1-39-05-a0", > mac2 => "44:1e:a1:39:05:a0", > ip => "192.168.2.1", > netmask => "255.255.0.0", > "node2": > mac1 => "78-e7-d1-24-5f-d0", > mac2 => "78:e7:d1:24:5f:d0", > ip => "192.168.2.2", > netmask => "255.255.0.0", > "node3": > mac1 => "78-e7-d1-24-5c-10", > mac2 => "78:e7:d1:24:5c:10", > ip => "192.168.2.3", > netmask => "255.255.0.0", > } #preseed > > include dhcpd > > } # node > > This is puppet module for preseed and dhcpd. > /etc/puppet/modules/preseed/manifests/init.pp: > class dhcpd { > package { "isc-dhcp-server": > ensure => installed, > } #package > service { "isc-dhcp-server": > ensure => $ensure, > enable => true, > require => Package["isc-dhcp-server"], > } #service > file { "/etc/default/isc-dhcp-server": > ensure => present, > path => "/etc/default/isc-dhcp-server", > mode => 644, > content => template("preseed/isc-dhcp-server.erb"), > require => Package["isc-dhcp-server"], > notify => Service["isc-dhcp-server"], > } #file > > } #class > > define preseed ($mac1 = dflt, $mac2 = undef, $ip, $netmask) { > include dhcpd > file { "/var/www/preseed_$name.cfg": > ensure => present, > mode => 644, > content => template("preseed/preseed_web.cfg.erb"), > } #file > file { "/var/lib/tftpboot/pxelinux.cfg/01-$mac1": > ensure => present, > mode => 644, > content => template("preseed/pxe-config.erb"), > require => File["/var/www/preseed_$name.cfg"], > } #file > file { "/etc/dhcp/dhcpd.conf-$name": > ensure => present, > path => "/etc/dhcp/dhcpd.conf", > mode => 644, > content => template("preseed/dhcpd.conf.erb"), > require => Package["isc-dhcp-server"], > notify => Service["isc-dhcp-server"], > } #file > > } #define > > dhcpd.conf.erb: > ... > <% name.each do |val| -%> > host <%= val %> { hardware ethernet <%= mac2 %>; fixed-address > <%= ip %>; } > <% end -%> > > When I try to apply this configuration, I receive this message: > > root@puppet:/# puppet agent --test --server=puppet.domain.com > info: Caching catalog for puppet.domain.com > err: Could not run Puppet configuration client: Cannot alias File[/etc/ > dhcp/dhcpd.conf-node1] to ["/etc/dhcp/dhcpd.conf"]; resource ["File", > ["/etc/dhcp/dhcpd.conf"]] already exists > > What is the best way to create a configuration that applies only to > one node, but have to contain different parameters for each node.Puppet is complaining that you have declared multiple file resources with the same path (/etc/dhcp/dhcpd.conf), which you have. Your manifest is therefore inconsistent: Puppet cannot satisfy all your declarations simultaneously. The problem in this case is this declaration inside your "preseed" definition: file { "/etc/dhcp/dhcpd.conf-$name": ... path => "/etc/dhcp/dhcpd.conf", ... } #file Note that you are giving a literal path to a resource declared within a defined type. That would work if you only declared one instance of the defined type, but it creates a conflict if you declare more than one. The solution looks easy in this case, because the problematic declaration doesn''t really depend on its context (that should have been your first clue that it didn''t belong there). Pull it out and make it a sibling of the preseed { ... } declaration block: preseed { "node1": ... } # preseed file { "/etc/dhcp/dhcpd.conf": ... } #file John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
> The problem in this case is this declaration inside your "preseed" > definition: > > file { "/etc/dhcp/dhcpd.conf-$name": > ... > path => "/etc/dhcp/dhcpd.conf", > ... > } #file > > Note that you are giving a literal path to a resource declared within > a defined type. That would work if you only declared one instance of > the defined type, but it creates a conflict if you declare more than > one. > > The solution looks easy in this case, because the problematic > declaration doesn''t really depend on its context (that should have > been your first clue that it didn''t belong there). Pull it out and > make it a sibling of the preseed { ... } declaration block: > > preseed { > "node1": > ... > > } # preseed > > file { "/etc/dhcp/dhcpd.conf": > ... > > } #file > > JohnHi, unfortunately this doesnt work. In preseed {...} i declare variables for each node, which are then used in file {"/etc/dhcp/dhcpd.conf":} in template content => template("preseed/dhcpd.conf.erb"). If I make file {"/etc/dhcp/dhcpd.conf":} sibling of preseed {...}, then variables from preseed are not available in template. I want to perform this. For each node I want to add one line into /etc/ dhcp/dhcpd.conf : ... host n1 { hardware ethernet 78:e7:d1:24:5c:10; fixed-address 192.168.1.1; } host n2 { hardware ethernet 78:e7:d1:24:5c:11; fixed-address 192.168.1.2; } host nx { hardware ethernet 78:e7:d1:24:5c:1@; fixed-address 192.168.1.x; } ... Jiri -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Jun 6, 7:34 am, Jiří Červenka <jiricerven...@gmail.com> wrote:> > The problem in this case is this declaration inside your "preseed" > > definition: > > > file { "/etc/dhcp/dhcpd.conf-$name": > > ... > > path => "/etc/dhcp/dhcpd.conf", > > ... > > } #file > > > Note that you are giving a literal path to a resource declared within > > a defined type. That would work if you only declared one instance of > > the defined type, but it creates a conflict if you declare more than > > one. > > > The solution looks easy in this case, because the problematic > > declaration doesn''t really depend on its context (that should have > > been your first clue that it didn''t belong there). Pull it out and > > make it a sibling of the preseed { ... } declaration block: > > > preseed { > > "node1": > > ... > > > } # preseed > > > file { "/etc/dhcp/dhcpd.conf": > > ... > > > } #file > > > John > > Hi, > unfortunately this doesnt work. In preseed {...} i declare variables > for each node, which are then used in file {"/etc/dhcp/dhcpd.conf":} > in template content => template("preseed/dhcpd.conf.erb"). > > If I make file {"/etc/dhcp/dhcpd.conf":} sibling of preseed {...}, > then variables from preseed are not available in template. > > I want to perform this. For each node I want to add one line into /etc/ > dhcp/dhcpd.conf : > ... > host n1 { hardware ethernet 78:e7:d1:24:5c:10; fixed-address > 192.168.1.1; } > host n2 { hardware ethernet 78:e7:d1:24:5c:11; fixed-address > 192.168.1.2; } > host nx { hardware ethernet 78:e7:d1:24:5c:1@; fixed-address > 192.168.1.x; }That does not change the fact that you are declaring multiple instances of your ''preseed'' defined type, but you want only one /etc/ dhcp/dhcpd.conf. You therefore cannot manage dhcpd.conf from the ''preseed'' defintion. Even if you could obscure the multiple- management (as you tried to do by using different resource titles), the result would not be what you are looking for: some one of the declarations would end up winning, instead of all of them cooperating as you hoped they would do. You need to give your dhcpd.conf template all the data it needs at once (which means pulling it out of ''preseed'', as I said), or else you need to use it differently. The former option probably requires you to load your node data into a more complex data structure, such as a hash (or array) of hashes, which the template would then process. The latter option probably involves using something like the Puppet::Concat module to build your dhcpd.conf file from multiple pieces, with each piece being a separate resource. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.