Dependencies between defines

1,323 views
Skip to first unread message

Axel Bock

unread,
Aug 22, 2012, 8:27:03 AM8/22/12
to puppet...@googlegroups.com
Hi readers

another question for my little puppet project: Can I (and if yes, how) define dependendies between puppet "defines"? (define like in define mymodule::mydefine() {...})

Example: I have a define "prepare_cool_thing" and another define "cool_thing". Both can be on a machine several times (quite, actually, like vhosts :). So this is entirely valid:

prepare_cool_thing{ "name1" : }
cool_thing{ "name1" : }

prepare_cool_thing{ "name2" : }
cool_thing{ "name2" : }

I'm sure you get it. BUT. I'd like to state within the cool_thing define that the prepare_cool_thing was executed. Can I do that? The following does not seem to do what I want:

Prepare_cool_thing[ "name1" ] -> Cool_thing[ "name1" ]  # naah, does not work.


Thanks & greetings!
Axel.

Martin Alfke

unread,
Aug 22, 2012, 9:06:09 AM8/22/12
to puppet...@googlegroups.com
Where did you put the dependency?
What puppet version are you using.

Normally this works:

define task_one ( $user = 'root' ) {
    file { '/tmp/one':
      owner => $user,
      content => $user,
   }
}
define task_two ( $user = 'root' ) {
   file { '/tmp/two':
      owner => $user,
      content => $user,
   }
}
task_one { 'foo': }
task_two { 'foo': }
Task_one['foo'] -> Task_two['foo']

You can also place the order inside the define:

define task_two ( $user = 'root') {
   file { '/tmp/two':
      owner => $name,
      content => $name,
   }
   Task_one["$name"] -> Task_two["$name"]
}





Thanks & greetings!
Axel.


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/zUkjN-osHugJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Axel Bock

unread,
Aug 23, 2012, 1:20:53 AM8/23/12
to puppet...@googlegroups.com
Hm, my last answer didn't get posted. So let's go again.

First, thanks for your help, it seems to work now - maybe I fixed another bug or did something wrong. But now I have another at which I'm stuck. Basically I configure our web servers with puppet. For that I have a "webserver" class which basically sets up only the environment for web service, and a preparevhost define which, well, prepares a vhost on the machine.

What puppet does now is to execute some of the preparevhost definitions _before_ the webserver class is applied, which fails miserably. EVEN though I defined a require => to a directory managed by the ws class from within the define - puppet simply seems to ignore that.

So how can I make sure that the webserver class gets applied fully before the prepvhost define is started? The node configuration looks like this now:

node 'server' { include webserver }
node 'host1' inherits 'server' { preparevhost {"url" : } }

I'd appreciate any help :) . Oh, and yes, my puppet version is 2.6.12 from SLES 11 SP2.


Thanks in advance & greetings!
Axel.

Douglas Garstang

unread,
Aug 23, 2012, 1:59:32 AM8/23/12
to puppet...@googlegroups.com
This really irks me. Is this documented anywhere? How did Task_one get
into scope inside Task_two? What is the scope for definitions? Are
they global?

Doug.

Martin Alfke

unread,
Aug 23, 2012, 2:21:50 AM8/23/12
to puppet...@googlegroups.com

On 23.08.2012, at 07:59, Douglas Garstang wrote:

...

>> Normally this works:
>>
>> define task_one ( $user = 'root' ) {
>> file { '/tmp/one':
>> owner => $user,
>> content => $user,
>> }
>> }
>> define task_two ( $user = 'root' ) {
>> file { '/tmp/two':
>> owner => $user,
>> content => $user,
>> }
>> }
>> task_one { 'foo': }
>> task_two { 'foo': }
>> Task_one['foo'] -> Task_two['foo']
>>
>> You can also place the order inside the define:
>>
>> define task_two ( $user = 'root') {
>> file { '/tmp/two':
>> owner => $name,
>> content => $name,
>> }
>> Task_one["$name"] -> Task_two["$name"]
>> }
>
> This really irks me. Is this documented anywhere? How did Task_one get
> into scope inside Task_two? What is the scope for definitions? Are
> they global?

My testcase run in a single manifest. So all defines are within the same scope.
In case that you use modules you need to give the full scope on ordering.

e.g.

Modue_one::Task_one['foo'] -> Module_two::Task_two['foo']


Axel Bock

unread,
Aug 23, 2012, 8:25:22 AM8/23/12
to puppet...@googlegroups.com
Ah maybe I'm too stupid but the whole puppet dependency resolution _seriously_ annoys me, so this is half a rant post, half a plea for someone to enlighten me about this dependency thing puppet has going.

I have another custom define which basically contains an exe and a file (directory). The file is not dependent on anything, but everywhere I use it I add a "require" to the define roughly like this:
my_rsync_define { ... require => something_else_before }.

unfortunately puppet simply does not care and tries do create the directory as the first step in the process, failing. this is not intuitive _at all_. the dot graph (I used graphviz a lot today) tells me that the DEFINE itself actually IS dependant on the something_else_before I added, but the DIRECTORY WITHIN THE DEFINE ... stands alone. I personally think this is ... not great. but maybe it's because I have an old version. File autorequires don't seem to work too well here, too, I think.






Am Mittwoch, 22. August 2012 14:27:03 UTC+2 schrieb Axel Bock:

Martin Alfke

unread,
Aug 23, 2012, 8:27:48 AM8/23/12
to puppet...@googlegroups.com
On 23.08.2012, at 14:25, Axel Bock wrote:

Ah maybe I'm too stupid but the whole puppet dependency resolution _seriously_ annoys me, so this is half a rant post, half a plea for someone to enlighten me about this dependency thing puppet has going.

I have another custom define which basically contains an exe and a file (directory). The file is not dependent on anything, but everywhere I use it I add a "require" to the define roughly like this:
my_rsync_define { ... require => something_else_before }.

unfortunately puppet simply does not care and tries do create the directory as the first step in the process, failing. this is not intuitive _at all_. the dot graph (I used graphviz a lot today) tells me that the DEFINE itself actually IS dependant on the something_else_before I added, but the DIRECTORY WITHIN THE DEFINE ... stands alone. I personally think this is ... not great. but maybe it's because I have an old version. File autorequires don't seem to work too well here, too, I think.

From my experience:

best is to add ordering to all resources.
- inside a define
- inside a class
- between classes








Am Mittwoch, 22. August 2012 14:27:03 UTC+2 schrieb Axel Bock:
Hi readers

another question for my little puppet project: Can I (and if yes, how) define dependendies between puppet "defines"? (define like in define mymodule::mydefine() {...})

Example: I have a define "prepare_cool_thing" and another define "cool_thing". Both can be on a machine several times (quite, actually, like vhosts :). So this is entirely valid:

prepare_cool_thing{ "name1" : }
cool_thing{ "name1" : }

prepare_cool_thing{ "name2" : }
cool_thing{ "name2" : }

I'm sure you get it. BUT. I'd like to state within the cool_thing define that the prepare_cool_thing was executed. Can I do that? The following does not seem to do what I want:

Prepare_cool_thing[ "name1" ] -> Cool_thing[ "name1" ]  # naah, does not work.


Thanks & greetings!
Axel.


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/9BNRHcD0VSoJ.

jcbollinger

unread,
Aug 27, 2012, 3:07:31 PM8/27/12
to puppet...@googlegroups.com


All declared resource instances and classes have global scope.  That includes resource instances of defined and custom types.


John

Reply all
Reply to author
Forward
0 new messages