Ask Your Question
0

consul watch puppet

asked 2016-06-17 10:50:56 -0600

Hello, I'm trying to setup a consul watch for a particular key and whenever it changes, i would like to invoke a puppet agent run. Are there any examples available for this? Can you please provide some guidelines as to how to go about it.

I tried setting up the watches for key and it doesn't seem to run the puppet agent when the key changes. May be i am doing something wrong here:
{ "watches": [ { "type": "keyprefix", "key": "pathtoconsul/web", "handler": "/etc/consul.d/my-key-handler.sh" } ] }

contents of /etc/consul.d/my-key-handler.sh: sudo puppet agent -t

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-06-17 20:58:25 -0600

DarylW gravatar image

There is a similar question here... haproxy and consul-template With a good answer from gareth.

The relevant watch code from the example is here..

::consul::watch { 'detect_backend_changes':
  type        => 'service',
  handler     => '/usr/bin/runpuppet.sh',
  service     => 'application',
  passingonly => true,
  require     => File['/usr/bin/runpuppet.sh'],
}

There is an external 'runpuppet' script that gets kicked off when there is a change in the available services.

edit flag offensive delete link more

Comments

Thank you very much. I will set it up this way and see if that works for me.

Redsmile gravatar imageRedsmile ( 2016-06-20 08:54:44 -0600 )edit

This invocation doesn't work for me because the ::consul::watch tries to install consul in the first place and gives me a ruby error, while I already have consul installed. I was looking for a JSON based approach to the watch. Thanks.

Redsmile gravatar imageRedsmile ( 2016-06-20 12:38:02 -0600 )edit
0

answered 2016-06-27 10:53:22 -0600

updated 2016-06-29 14:31:11 -0600

DarylW gravatar image

I finally got this working by writing a manifest with consul watch command similar to the one blow:

class consul_watch{

  $war_url= hiera('url_from_consul',[])

  notice("\$war_url comes back as  ${war_url}")


  file { '/.../consulwatch.sh':
    notify  => Service['consulwatch'],
    mode    => '0755',
    owner   => 'root',
    group   => 'root',
    content => "#!/bin/bash \n sudo consul watch -type key -key ${war_url} /.../my-key-handler.sh & \n",
  }
  service { 'consulwatch':
    ensure     => 'running',
    provider   => 'base',
    start      => '/.../consulwatch.sh',
    pattern    => 'consul watch',
    hasstatus  => true,
    hasrestart => true,
  }
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-06-17 10:50:56 -0600

Seen: 195 times

Last updated: Jun 29 '16