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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to