Please help with control/ordering issue

37 views
Skip to first unread message

dc1...@gmail.com

unread,
Feb 4, 2014, 6:11:14 PM2/4/14
to puppet...@googlegroups.com
Hi, im trying to work some logic into a puppet class and I'm not sure the best way to do it.  For this application, I have an installation phase, a setup phase, and then a maintenance phase.

My current method of maintaining this is to call the relevant subclass using "include".  I then  have to go comment out two of the 3 includes depending on which phase i'm on.  This of course means that I have to shut off puppet on all the nodes im not directly working on.

I would like to use the following logic in my class to control this.  Could somebody help me with the proper syntax to get this working?


class myapp {

  Class['myapp::phase1'] only if [ ! -e /path/to/puppet.phase ]
    # myapp::phase1 will echo 'phase2' into /path/to/puppet.phase  once all requirements are met

  Class['myapp::phase2'] only if [ $(cat /path/to/puppet.phase) == 'phase2' ]
    # myapp::phase2 will echo 'phase3' into /path/to/puppet.phase  once all requirements are met

  Class['myapp::phase3'] only if [ $(cat /path/to/puppet.phase) == 'phase3' ]
}


Jason Antman

unread,
Feb 5, 2014, 7:07:50 AM2/5/14
to puppet...@googlegroups.com
Unnamed poster,

Succinctly: You're trying to write a bash script in Puppet. That's not how it works, that's not what it's designed for, that's not how it should be used.

However, luckily, there's a really simple and easy way to do what you're trying to in Puppet:

    Class['myapp::phase1'] -> Class['myapp::phase2'] -> Class['myapp::phase3']

If there are *specific* things that you need to make sure happen before a given action (like making sure a package is installed before a config file is created/changed), that's what "requires" is for.

You may want to refer to John Bollinger's 2014-01-03 reply to the "wondering if I want to[sic] much now" thread, which gives some excellent descriptions on 'how not to Puppet':
https://groups.google.com/d/msg/puppet-users/IGqjPpVCrKA/VcUKiV3xfPkJ

-Jason
--
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/2c4124a2-dfd1-4006-b5c0-b66e026dfe5e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


dc1...@gmail.com

unread,
Feb 5, 2014, 8:57:46 AM2/5/14
to puppet...@googlegroups.com
Thanks, I will take a look at that post.
I haven't been able to find the "proper" way to do some of these things.

Initially I had this running as a single class,  working only with requires, before, and notify.

 This is where I ran into trouble,   maybe you know of an alternate way to achieve this.

During my initial setup,  I start with a simple package, file service relationship.
Next i need to add some users into the service which was just added.  For this, the service needs to be running   (ensure => running).

However,  after that initial installation is done.  I want the admin to have the ability to stop the service, without worrying that puppet is going to turn it back on.
So i got rid of ensure=>running,  and instead used an Exec[] (refreshonly) to start my service.  The Package notifies the exec

Now to add users.
I cannot "require" the Exec, because that only happens if after the RPM is installed

I keep running into cases where if I fix A, then B  breaks.  If i fix B, then C breaks.  if I fix C then A breaks again..
This is why I broke it into phases.




Jason Antman

unread,
Feb 5, 2014, 12:32:58 PM2/5/14
to puppet...@googlegroups.com
On 02/05/2014 08:57 AM, dc1...@gmail.com wrote:
> Thanks, I will take a look at that post.
> I haven't been able to find the "proper" way to do some of these things.
>
> Initially I had this running as a single class, working only with
> requires, before, and notify.
>
> This is where I ran into trouble, maybe you know of an alternate
> way to achieve this.
>
> During my initial setup, I start with a simple package, file service
> relationship.
> Next i need to add some users into the service which was just added.
> For this, the service needs to be running (ensure => running).
>
> However, after that initial installation is done. I want the admin
> to have the ability to stop the service, without worrying that puppet
> is going to turn it back on.
> So i got rid of ensure=>running, and instead used an Exec[]
> (refreshonly) to start my service. The Package notifies the exec
This is a common problem. It's been the problem with what I call "old
world" thinking every time I've done a new Puppet deployment at a shop
that isn't used to doing things in a sane, infrastructure-as-code way.
Why do you want to stop a service that should be running? Either the
service should be running, or it shouldn't.

If there's an emergency, the admin should either (a) complete their work
in < a puppet run interval, or (b) `puppet agent --disable` (which
ideally also throws some monitoring alerts) and stop the service. The
way I've generally approached this problem is by finding out under what
conditions an admin would have to stop the service, and teaching puppet
to handle them. That being said, I can't say I can think of many
services I have that I actually *want* stopped, ever.
>
> Now to add users.
> I cannot "require" the Exec, because that only happens if after the
> RPM is installed
>
> I keep running into cases where if I fix A, then B breaks. If i fix
> B, then C breaks. if I fix C then A breaks again..
> This is why I broke it into phases.
So I'll admit that, especially with proprietary software, it can be very
difficult to shoehorn broken installation processes into a sane
framework (Puppet).

On a side note, the process you're talking about is strikingly similar
to how one goes about installing and setting up RabbitMQ (at least 1.x)
- install the RPM, start the service, but then to add users you need to
have the admin plugin, and to make that active you need to restart the
service. It's entirely possible to do though - you might benefit from
some of the patterns used in
https://github.com/puppetlabs/puppetlabs-rabbitmq
>
>
>
>
> --
> 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/896ed69c-06d9-424e-b218-a0c117233196%40googlegroups.com.

D C

unread,
Feb 5, 2014, 2:27:26 PM2/5/14
to puppet...@googlegroups.com
The application does use rabbitmq which is the cause for my woes.

The chaining arrows will work to enforce the order,  but it doesn't help with the onlyif portion...

Class['myapp::phase1'] only if [ ! -e /path/to/puppet.phase ]


The alternative which I was trying to avoid was to go and dig through every item in each of the classes.
For some items i will have to add an only if.  Others will be just fine by using the regular before and require.  This should work but now I have to consider a bunch of test scenarios.


I'll take a look at that rabbit class to see what they did



Thanks,
Dan


Jason Antman

unread,
Feb 6, 2014, 7:45:06 AM2/6/14
to puppet...@googlegroups.com
If it uses RabbitMQ, I'd very very strongly advise that you just use the puppetlabs-rabbitmq module to configure the rabbitmq portion.

-Jason
Reply all
Reply to author
Forward
0 new messages