----- Original Message -----
> From: "jcbollinger" <[email protected]>
> To: [email protected]
> Sent: Wednesday, August 20, 2014 2:01:09 PM
> Subject: [Puppet Users] Re: "require" broken with create_resources() ?
> 
> 
> 
> On Wednesday, August 20, 2014 6:04:56 AM UTC-5, Vincent Miszczak wrote:
> >
> > Hello,
> >
> > I have a define like this :
> >
> > define application::install($root,$url,$user="root")
> > {
> >  include git
> >  #Puppet wants a command to start with /something...
> >  $cmd="/bin/echo 1&&{ cd $root||mkdir $root&&cd $root ; }&&git clone -b
> > prod $url ."
> >  $unless="/bin/ls -alh $root |grep '.git'"
> >
> >
> >  exec{"$cmd":
> >  command=>$cmd,
> >  unless=>$unless,
> >  user=>$user,
> >  require=>Package["git"]
> >  }
> > }
> >
> >
> > being called with a class :
> >
> > class applications($apps)
> > {
> >   create_resources(application::install,$apps)
> > }
> >
> >
> > and
> > $apps = {
> >    test => {
> >      url=> "https://mygitrepos/myapp.git";,
> >      root=> "/opt/apps/myapp",
> >      user=>"root",
> >      require=>Class[myclass],
> >    }
> > }
> >
> >
> > class "myclass" is included by some other module
> >
> > I get :
> >
> > Error: Could not retrieve catalog from remote server: Error 400 on SERVER:
> > Invalid relationship: Application::Install[test] { require =>
> > Class[myclass] }, because Class[myclass] doesn't seem to be in the catalog
> >
> > but the class *is* really included.
> >
> > For instance, if I do not require in $apps but require in the exec{}, it
> > will work just fine. Ofc I won't do this because I need things to be
> > dynamic.
> >
> > Expected behavior is it should work, unless I missed something.
> >
> > Any help welcome.
> >
> >
> 
> I'm a bit surprised to hear that doesn't work when the hash passed to
> create_resources() is initialized via a literal, as you show.  If that's
> how you plan to do it, though, then you could instead establish the
> relationship separately by use of the chain operator:
> 
>     Class['myclass'] -> Application::Install['test']
> 
> That's not really what I'd call "dynamic", however, so I suspect what
> you're really trying to do is express that hash in hiera data.  Indeed that
> *won't* work, at least not with the default back-end (YAML), because YAML
> has no mechanism for expressing Puppet resource references.  The value
> "Class[myclass]" is just a string in YAML.  You could work around such a
> problem by expressing required class names in your data rather than class
> references (and then applying the chain operator appropriately in your
> defined type).


It seems to work fine for me, the code below does what you'd expect:

   class myclass {
    notify{"woop": }
   }

   include myclass

   $resources = {"/usr/bin/cowsay 'it works fine'" => {"logoutput" => "true", 
"require" => Class[myclass]}}

   create_resources("exec", $resources)

It also works if you quote the 'Class[myclass]' so it should work if it comes 
from JSON or whatever

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/964991067.414.1408540263490.JavaMail.zimbra%40devco.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to