duplicated resource with an exported resource

535 views
Skip to first unread message

Jose Luis Ledesma

unread,
Jul 12, 2014, 7:05:35 AM7/12/14
to puppet...@googlegroups.com

Hi all,

    I have found a problem setting up exported resources. The problem is that for every hosts I want to define in its /etc/hosts the primary ip, but I want to export a secondary ip with the same hostname that will be collected just by one server. So I defined:

 

@@host { $::hostname :

  ensure  => present,

  ip      => $secondary_ip,

}

 

host { $::hostname :

  ensure  => present,

  ip      => $primary_ip

}

 

 

but when I launch puppet a duplicated resource arises:

 

# puppet agent -t

Info: Retrieving plugin

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Host[XXXXX] is already declared in file /etc/puppet/manifests/init.pp:15; cannot redeclare at  /etc/puppet/manifests/init.pp:5 on node XXXX

Warning: Not using cache on failed catalog

Error: Could not retrieve catalog; skipping run

 

I have just implemented a workaround:


@@host { "${::hostname}-secondary" :

  ensure  => present,

  ip      => $secondary_ip,

  host_alises => $::hostname,

}

 

but I wanted to know if there is a better solution.

 

thanks,

Juan Sierra Pons

unread,
Jul 14, 2014, 4:34:30 AM7/14/14
to puppet...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/bc657bc3-9659-46b4-b713-26d9ebea9f64%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Hi,

I think there is not better soluction as titles must be unique per
resource type [1]

Your solution seems ok for me

[1]http://docs.puppetlabs.com/puppet/latest/reference/lang_resources.html#title

Best regards
--------------------------------------------------------------------------------------
Juan Sierra Pons ju...@elsotanillo.net
Linux User Registered: #257202
Web: http://www.elsotanillo.net Git: http://www.github.com/juasiepo
GPG key = 0xA110F4FE
Key Fingerprint = DF53 7415 0936 244E 9B00 6E66 E934 3406 A110 F4FE
--------------------------------------------------------------------------------------

José Luis Ledesma

unread,
Jul 14, 2014, 6:22:13 AM7/14/14
to puppet...@googlegroups.com
Hi,

   Shall this be a bug? Teorically a exported resource is not applied in the managed node if you don't collect it, so it should not collide with an "applied" resource. thoughs?

thanks,



For more options, visit https://groups.google.com/d/optout.



--
José Luis Ledesma

Juan Sierra Pons

unread,
Jul 14, 2014, 6:32:19 AM7/14/14
to puppet...@googlegroups.com
2014-07-14 12:21 GMT+02:00 José Luis Ledesma <joseluis...@gmail.com>:
> Hi,
>
> Shall this be a bug? Teorically a exported resource is not applied in the
> managed node if you don't collect it, so it should not collide with an
> "applied" resource. thoughs?
>
> thanks,

Hi

From [1] Docs: Language: Exported Resources
"
Uniqueness

Every exported resource must be globally unique across every single
node. If two nodes export resources with the same title or same
name/namevar and you attempt to collect both, the compilation will
fail. (Note: Some pre-1.0 versions of PuppetDB will not fail in this
case. This is a bug.)

To ensure uniqueness, every resource you export should include a
substring unique to the node exporting it into its title and
name/namevar. The most expedient way is to use the hostname or fqdn
facts.
"

Have a look to this other link [2] Collecting duplicate resources in puppet

[1] http://docs.puppetlabs.com/puppet/latest/reference/lang_exported.html#uniqueness
[2] http://ttboj.wordpress.com/2013/06/04/collecting-duplicate-resources-in-puppet/

Hope it helps

Kristof Willaert

unread,
Jul 14, 2014, 7:40:42 AM7/14/14
to puppet...@googlegroups.com
Hi,

I think you should be able to use the exported resource on both the remote node, and the node that
exports it, by using collection both local and remote and overriding the necessary attribute:

On host A:

@@host { $::hostname :

  ensure  => present,

  ip      => $secondary_ip,

}


Also on host A:


Host <<| title == '$::hostname'|>> { ip => $primary_ip }



On host B (the remote host):

Host <<| title == 'hostA'|>>



Kind regards,


kristof



On Mon, Jul 14, 2014 at 10:33 AM, Juan Sierra Pons <ju...@elsotanillo.net> wrote:

jcbollinger

unread,
Jul 14, 2014, 9:29:22 AM7/14/14
to puppet...@googlegroups.com
It may be possible to wrap the duplicate Host resource in an exported defined type instance:

define site::secondary_host ($ip, $ensure = 'present') {
  host { $title: ip => $ip, ensure => $ensure }
}

@@site::secondary_host { ${::hostname}:
  ip => $secondary_ip
}

You will not be able to collect that resource on the node that exports it (you would again -- and rightfully -- get a duplicate resource complaint), but I think otherwise you should be ok.  Specifically, I think Puppet will avoid evaluating the definition body for instances that are exported, until and unless they are collected.  If that indeed works then it may be a bit better than your solution because it makes the node's hostname the primary name of the hosts entry, rather than an alias.


John

jcbollinger

unread,
Jul 14, 2014, 9:42:19 AM7/14/14
to puppet...@googlegroups.com


On Monday, July 14, 2014 5:22:13 AM UTC-5, Jose Luis Ledesma wrote:
Hi,

   Shall this be a bug? Teorically a exported resource is not applied in the managed node if you don't collect it, so it should not collide with an "applied" resource. thoughs?



I understand your argument, but it is by no means clear that the scope for the uniqueness constraint should be the catalog into which the resource is placed.  In fact, Puppet consistently works differently, as duplicate virtual resources are also not allowed, even if there is no attempt to collect or realize them at all.  The constraint can be conceptualized as requiring uniqueness of all the resources known within the scope of a given catalog compilation run.  It's a valid design decision.


John

Kristof Willaert

unread,
Jul 14, 2014, 9:55:38 AM7/14/14
to puppet...@googlegroups.com
[snip]

You will not be able to collect that resource on the node that exports it (you would again -- and rightfully -- get a duplicate resource complaint), but I think otherwise you should be ok. 

The documentation for exported resources suggests otherwise:

Any node (including the node that exported it) can then collect the exported resource and manage its own copy of it. [1]

I must say I haven't tried it myself, but unless I misinterpret the sentence above, it should be possible.

José Luis Ledesma

unread,
Jul 14, 2014, 10:35:50 AM7/14/14
to puppet...@googlegroups.com
really nice workaround, thanks!


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
José Luis Ledesma

jcbollinger

unread,
Jul 15, 2014, 9:24:53 AM7/15/14
to puppet...@googlegroups.com


On Monday, July 14, 2014 8:55:38 AM UTC-5, Kristof Willaert wrote:
[snip]

You will not be able to collect that resource on the node that exports it (you would again -- and rightfully -- get a duplicate resource complaint), but I think otherwise you should be ok. 

The documentation for exported resources suggests otherwise:

Any node (including the node that exported it) can then collect the exported resource and manage its own copy of it. [1]

I must say I haven't tried it myself, but unless I misinterpret the sentence above, it should be possible.


You're not misinterpreting the docs, but you are misinterpreting my statement.  Although generally the node exporting a resource can collect that resource, if the OP used the approach I described then his nodes would not be able to collect the Site::Secondary_host resources they declare themselves.  If they tried to collect their own, then it would yield a duplicate Host resource (from the defined type body; because he already, separately, declares a Host for the node itself).  The key there is that -- I think -- the type's body will not be evaluated by the declaring node for instances that it does not collect, even those that it declares itself.


John

José Luis Ledesma

unread,
Jul 15, 2014, 3:23:13 PM7/15/14
to puppet...@googlegroups.com

It worked as you thought.

Many thanks, perhaps the code is not so nice, but the config applied is, by far, better.

Regards,

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

Jason Antman

unread,
Jul 30, 2014, 8:42:49 AM7/30/14
to puppet...@googlegroups.com
Just in case anyone comes by this in the future, maybe I'm missing something, but why not keep this really simple (did you read the type reference docs for host?):

@@host { "${::hostname}_exported" :

  name    => $::hostname,

  ensure  => present,

  ip         => $secondary_ip,

}

 

host { $::hostname :

  ensure  => present,

  ip      => $primary_ip

}

José Luis Ledesma

unread,
Jul 31, 2014, 3:43:42 AM7/31/14
to puppet...@googlegroups.com
Hi,

  this doesn't work. You cannot have two resources with the same name:

 Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Host[XXXX] is already declared in file XXXXX/init.pp:17; cannot redeclare at XXXX/host.pp:5 on node XXXXX

regards,



For more options, visit https://groups.google.com/d/optout.



--
José Luis Ledesma

jcbollinger

unread,
Jul 31, 2014, 9:26:28 AM7/31/14
to puppet...@googlegroups.com


On Thursday, July 31, 2014 2:43:42 AM UTC-5, Jose Luis Ledesma wrote:
Hi,

  this doesn't work. You cannot have two resources with the same name:

 Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Host[XXXX] is already declared in file XXXXX/init.pp:17; cannot redeclare at XXXX/host.pp:5 on node XXXXX



Yes, although $title does not have to be the same as $name, Puppet enforces that (Type, $title) and (Type, $name) are both unique (with respect to the same collection, even).


John

Reply all
Reply to author
Forward
0 new messages