Hi Arfoz,

this is the best example on how to _not_ do classes.
Every class should be self contained - as long as possible.
In your case you have a hard reference from one resource inside a class to 
another resource inside another class.
I always tell my training course attendees that they should never do this 
unless they don’t like themselves and they want to have Puppet nightmares.

In your case you can do the following hack:

make the add file class a parameterised class, set the parameter to the default 
behaviour:

class addfile (
  $enable_notify => Service[’tomcat’],
) {
  file {‘/tmp/hello’:
    ensure => file,
    notify => $enable_notify,
  }
}

On systems where you don’t have tomcat class included you have to declare the 
class add file with parameter set to undef.

But: be aware that even this is not a good solution.
It’s just a hack.
Try to refacter your modules.

Best,
Martin


On 31 Mar 2016, at 13:48, Afroz Hussain <hussainaph...@gmail.com> wrote:

> Error as below:
> 
> Error: Could not retrieve catalog from remote server: Error 400 on SERVER: 
> Invalid relationship: File[/tmp/hello] { notify => Service[tomcat] }, because 
> Service[tomcat] doesn't seem to be in the catalog
> 
> On Thursday, 31 March 2016 17:13:46 UTC+5:30, Afroz Hussain wrote:
> Hi All,
> 
> I am facing an issue to notify a service from different module whenever file 
> changes.
> Example:
> I have a addfile module which creates a file and want to notify tomcat 
> service which is present in tomcat module. 
> 
> class addfile {
>    file {"/tmp/hello":
>      ensure => file,
>      content => "hello",
>      notify   => Service["tomcat'],
>    }
> }
> 
> 
> it is throwing an error as tomcat service is not in catalog.
> 
> I have 3.6.2 version of puppet and using ENC.
> 
> Any help will be appreciated
> 
> Thanks,
> Afroz Hussain
> 
> 
> -- 
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/02cfc06d-d306-48a2-a917-7144606a1509%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/4E500FF9-67BF-4683-8929-AC0DA2FCDC31%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to