Trouble with notify/require/before/subscribe

43 views
Skip to first unread message

Stack Kororā

unread,
Jan 30, 2014, 5:00:49 PM1/30/14
to puppet...@googlegroups.com
Greetings,
I am trying to puppetize a process that goes like this:
1) remove package a.i386
2) create repo file
3) install package a.x86_64 from repo
4) update config_file_1
5) update config_file_2
6) update config_file_3
7) start service

Shouldn't be too hard right? Except I have played with every combination I can think of using with notify, subscribe, before, and require and I can't seem to get this to all happen in the same run. It always does a part of it the first run then requires a second run to finish up (a couple of variations required three and even four runs!). I am struggling to find out where I am going wrong. The code I have right now is the "best" in that it always requires _just_ two runs to complete. I edited out a lot of the parameters that are trivial just to focus on the dependency problem. I can share full code if I really need to but it is a bit messy as I pass all kinds of stuff to the template and I don't want to confuse the issue.

Here is the basis of my code:

package { ['a.i386']:
  ensure => absent,
  before => Package['a.x86_64'],
}

yumrepo { "RepoA":
  # stripped out other paramters
  notify => Package['a.x86_64'],
}

package { ['a.x86_64']:
  ensure => absent,
  subscribe => Yumrepo['RepoA'],
}

file { "/etc/config_file_1":
  # stripped out other paramters
  subscribe => Package['a.x86_64'],
}

file { "/etc/config_file_2":
  # stripped out other paramters
  subscribe => Package['a.x86_64'],
}

file { "/etc/config_file_3":
  # stripped out other paramters
  subscribe => Package['a.x86_64'],
}

service { 'a':
  # stripped out other paramters
  subscribe => File["/etc/config_file_1","/etc/config_file_2","/etc/config_file_3"],
}

As stated, I get a consistent run out of this. I just have to do it twice.
First run:
a.i386 is removed
Yumrepo is created
scheduling refresh of service
All three files fail to install
service fails

Second run
a.x86_64 is created
scheduling refresh of service
All three files install
service works

Why?

According to this page [1] subscribe "Causes a resource to be applied after the target resource. The subscribing resource will refresh if the target resource changes." Thus the scheduling of a refresh shouldn't happen until /after/ the files and NONE of the files are supposed to run until /after/ the package is installed! But clearly, this is not the case! At least the service schedule happens after the files fail so that is somewhat in order. And the repo is created properly, so that is a plus. I have a feeling that it is because the yum repo isn't refreshed before trying to install the package, but I am not 100% sure on that. As far as I can tell through debug, puppet never even attempts to install a.x86_64 until the second run.
[1] http://docs.puppetlabs.com/puppet/latest/reference/lang_relationships.html

The only thing left that I can think of that I haven't tried would be to shove each process into a subclass then chain them together something like this {class::remove}->{class::addyum}->{class::install}->{class::configfiles}->{class::service} but that seems /really/ silly.

Can someone please point out where things are going screwy for me? I would greatly appreciate it.

Thanks!

Message has been deleted

Luis León

unread,
Jan 31, 2014, 6:25:07 AM1/31/14
to puppet...@googlegroups.com
I use arrows to specify the order without class, you could use:

Package['a.i386']->Yumrepo ['RepoA']->Package ['a.x86_64']->File ['/etc/config_file_1] and so on...


For example now I'm working with mongo and I use a single class with the previous dependence:

Package['mongo-10gen-server-2.
2.6']->File[$paths]->File['/etc/mongo/arbiter.conf']->File['/etc/mongo/shard1_master.conf']->File['/etc/mongo/shard1_secondary.conf']->File['/etc/init.d/mongod']->Service['mongod']->File['/etc/puppet/rs.js']->Exec["mongo $ip:$port_replica/admin /etc/puppet/rs.js"]


Regards,
Luis

Stack Kororā

unread,
Jan 31, 2014, 7:40:38 AM1/31/14
to puppet...@googlegroups.com
Greetings,

Huh. I don't know why, but for some silly reason I thought I had to use subclasses with arrows. I will re-work my script with them and see how it goes.

Thanks! I appreciate the suggestion.

zerozer...@gmail.com

unread,
Jan 31, 2014, 8:21:05 AM1/31/14
to puppet...@googlegroups.com
On Friday, January 31, 2014 1:40:38 PM UTC+1, Stack Kororā wrote:

Huh. I don't know why, but for some silly reason I thought I had to use subclasses with arrows. I will re-work my script with them and see how it goes.

Hi,
I'll add that chaining arrows between single resources can quickly become cumbersome when the number of resources starts increasing (more files, more packages…).
I worked around this by using tags and resource collectors.

You can set tags as default attributes for the resource types you are using, e.g.:

Package {
    tag => "my-packages",
  }

File {
    tag => "my-files",
}

Service {
    tag => "my-services",
}

And then you can use resource collectors to define dependencies between your tagged types:

Package <| tag == "my-packages" |>
->
File <| tag == "my-files" |>
~>
Service <| tag == "my-services" |>

(Writing dependencies on separate lines makes them easier to read and understand IMHO)

-- 
Marco

Reply all
Reply to author
Forward
0 new messages