Run command on one server when a file updates on another

44 views
Skip to first unread message

Larry Jacobson

unread,
Dec 20, 2016, 12:05:52 PM12/20/16
to Puppet Users
I want to update a service on a server (server B) when a file changes on a different server (serverA).  I am using stored configs with puppetdb.  
When I do something like the code below I get the following error message

Error 400 on SERVER: Invalid relationship: File[/etc/test.txt] { notify => Exec[command_on different_server] }, because Exec[command_on different_server] is exported but not collected

Am I on the right track?  I can't seem to figure it out how to do this.



class serverA {

    file { "/etc/test.txt":
                mode => 644,
                source => "puppet:///modules/nagios/test.txt",
                notify => Exec["command_on different_server"],

     }

    @@exec { "command_on_different_server":
         command => "/usr/bin/command_whaterver",
         tag => "tag_command",
     }
}
=====================

class serverB {

         Exec <<| tag == "tag_command" |>> {}

}

     



Martin Alfke

unread,
Dec 30, 2016, 6:36:15 AM12/30/16
to puppet...@googlegroups.com

> On 20 Dec 2016, at 17:35, Larry Jacobson <larj...@gmail.com> wrote:
>
> I want to update a service on a server (server B) when a file changes on a different server (serverA). I am using stored configs with puppetdb.
> When I do something like the code below I get the following error message
>
> Error 400 on SERVER: Invalid relationship: File[/etc/test.txt] { notify => Exec[command_on different_server] }, because Exec[command_on different_server] is exported but not collected
>
> Am I on the right track? I can't seem to figure it out how to do this.

You are on the right track.
Maybe the following will work:

class server_a::configfile {
file { ‘/etc/text.txt’:
ensure => file,
...
}
}

class server_a::command {
@@exec { ‘run command’:
tag => ‘command’,

}
}

class server_a {
contain server_a::configfile
contain server_a::command

Class[‘server_a::configfile’] ~> Class[‘server_a::command’]
}

class server_b {
Exec <<| tag == ‘command’ |>>
}

The ~> notify/subscribe chaining on the class will propagate the notify/subscribe to the resources inside the class.


>
>
>
> class serverA {
>
> file { "/etc/test.txt":
> mode => 644,
> source => "puppet:///modules/nagios/test.txt",
> notify => Exec["command_on different_server"],
>
> }
>
> @@exec { "command_on_different_server":
> command => "/usr/bin/command_whaterver",
> tag => "tag_command",
> }
> }
> =====================
>
> class serverB {
>
> Exec <<| tag == "tag_command" |>> {}
>
> }
>
>
>
>
>
>
> --
> 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/62a9eb9d-fd73-4dea-8d35-b74211b20e6b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

armstron...@yahoo.com

unread,
Dec 30, 2016, 5:22:11 PM12/30/16
to puppet...@googlegroups.com

--------------------------------------------
On Fri, 12/30/16, Martin Alfke <tux...@gmail.com> wrote:

Subject: Re: [Puppet Users] Run command on one server when a file updates on another
To: puppet...@googlegroups.com
Date: Friday, December 30, 2016, 1:36 PM
https://groups.google.com/d/msgid/puppet-users/EB4FEF36-DD2F-469E-B5B4-B31CC9796FBE%40gmail.com.
For more options, visit
https://groups.google.com/d/optout.ituatia romanilor din Bucovina s-a inrautatit in toamna anului 1918 cand ustro-Ungaria practic se prabusise. Se vehicula teza anexarii de catre absburgi ca o ultima solutie de salvare a Bucovinei la Galitia in timp ce craina ridica pretentii de stapanire asupra provinciei romanesti si ameninta cu terventia armata. Din initiativa lui Sextil Puscariu si lancu Flondor s-a jnvoca't in aceste conditii la 14 27 octombrie 1918 o Adunare a sprezentantilor populatiei romanesti din provincie. Aceasta a decis unirea ucovinei cu teritoriile locuite de romani din Austro-Ungaria acum practic rabusita. S-a ales un Comitet Executiv si un Consiliu National. Lider politic a ist ales lancu Flondor. Populatia romaneasca si-a manifestat astfel libera de rice ingerinta vointa de a se uni cu tara. Interventia trupelor ucrainene l-a eterminat insa pe Flondor sa ceara sprijinul armatei romane.
Reply all
Reply to author
Forward
0 new messages