Exported define with facts

asked 2014-11-05 17:18:35 -0500

Glueon gravatar image

updated 2014-11-05 17:19:10 -0500

I found out that if I use a fact in an exported define it gets substituted by facts of the node I realize it on. But if use a class with an exported resource (file in my example) everything works just fine.

Here is my sample:

class exportedResource($url) {
  @@file { "/etc/openvpn/${::fqdn}" :
    ensure   => present,
    content => "${url} ${::fqdn}"
  }
}

define exporteddefine($url) {
  file { "/etc/openvpn/${::fqdn}.define" :
    ensure  => present,
    content => "${url} ${::fqdn}"
  }
}

class collect($url) {
  @@exporteddefine { "${::fqdn}_define" : url => $url }
}
node 'agent1.exmple.com' {
  class { 'exportedResource' : url     => $url }
  class { 'collect' : url => 'http://agent2.com' }
}

node 'puppet.example.com' {
  File <<| |>>
  Exporteddefine <<| |>>
}

I expected to have these file on puppet.example.com:

  • /etc/openvpn/agent1.example.com
  • /etc/openvpn/agent1.example.com.define

But actually i got:

  • /etc/openvpn/agent1.example.com
  • /etc/openvpn/puppet.example.com.define

I thought that define should work the same as a class and it should be exported with the facts of the machine I exported it from. Am I doing it wrong or it's how it works and the only solution is too pass $::fqdn as a param? Like this:

define exporteddefine($url, $my) {
   file { "/etc/openvpn/${my}.define" :
     ensure  => present,
     content => "${url} ${my}"
   }
 }

class collect($url) {
    @@exporteddefine { "${::fqdn}_define" : my => $::fqdn. url => $url }
}
edit retag flag offensive close merge delete

Comments

1

I'm a bit stumped. The behavior of exported defined types isn't covered by the docs, as best I can tell. I'll have to dig for an answer.

cbarbour gravatar imagecbarbour ( 2014-11-06 17:31:40 -0500 )edit

Don't really want to bother, but are there any news from you about the issue?

Glueon gravatar imageGlueon ( 2014-11-10 17:47:21 -0500 )edit

None yet. Perhaps try exporting the file resource rather than the defined type?

cbarbour gravatar imagecbarbour ( 2014-11-10 18:21:39 -0500 )edit

No. Because exporting define i export everything within the define. Just in this example there is only one resource, in a real one it's convenient to export the whole define. The solution is to pass all facts as params to define. Then it works. The question is why class works differently.

Glueon gravatar imageGlueon ( 2014-11-11 04:40:45 -0500 )edit