Ordering between 2 create_resources in Puppet Manifests

1,838 views
Skip to first unread message

Vishwa Kumba

unread,
Mar 29, 2014, 9:48:26 AM3/29/14
to puppet...@googlegroups.com
I was wondering if there is a way to define ordering between 2 create_resources in puppet manifests.

For example:

create_resources('php::install', $php_packages)  ->
create_resources('webapps::deploy', $apps)

The above does not work, but does puppet support the ordering between 2 create_sources statements?
I need my webapps to be deployed after the required packages have been installed.

I have seen a syntax like this below. Here class['apache'] seems to be execued before the create_resources here.

include apache
Class['apache'] -> Webapps::Deploy_files <| |>
create_resources('webapps::deploy_files', $apps)

Is there any puppet documentation on this strange syntax <| |>? Using this syntax, is it possible to call create_resources before and after a class declaration?


-Vishwa

Denmat

unread,
Mar 29, 2014, 5:29:35 PM3/29/14
to puppet...@googlegroups.com
Hi,

Yes there is at least one way. I have been using tags to achieve this like so:

$default_a = { tag => 'do_a' }
$some_hasha = hiera('a')
$default_b = { tag => 'do_b' }
$some_hashb = hiera('b')

create_resource(resource_type, $some_hasha, $default_a)

create_resource(resource_type, $some_hashb, $default_b)

Resource_type<| tag == 'do_a' |> -> Resource_type<| tag == 'do_b' |>

You should also be able to tag in your yaml 'a' or 'b' hash but you have to tag every hash throughout the hierarchy (which could lead to unexpected results if you forget).

Den
--
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/2e1fb72d-02e3-4c1d-a552-23090ad6be06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
Mar 31, 2014, 10:34:18 AM3/31/14
to puppet...@googlegroups.com


On Saturday, March 29, 2014 8:48:26 AM UTC-5, Vishwa Kumba wrote:
I was wondering if there is a way to define ordering between 2 create_resources in puppet manifests.

For example:

create_resources('php::install', $php_packages)  ->
create_resources('webapps::deploy', $apps)

The above does not work, but does puppet support the ordering between 2 create_sources statements?


Yes and no.  Puppet evaluates those statements in the order they appear in the manifest file, so in that sense you don't need special ordering operators.  But that's part of catalog compilation.  What you really are after is to influence the relative order of application of the resources declared via the two create_resources() calls.

 
I need my webapps to be deployed after the required packages have been installed.

I have seen a syntax like this below. Here class['apache'] seems to be execued before the create_resources here.

include apache
Class['apache'] -> Webapps::Deploy_files <| |>
create_resources('webapps::deploy_files', $apps)

Is there any puppet documentation on this strange syntax <| |>?


Yes: http://docs.puppetlabs.com/puppet/3/reference/lang_collectors.html.  See also http://docs.puppetlabs.com/puppet/3/reference/lang_virtual.html#realizing-with-a-collector.

I would recommend you read through the entire DSL reference, though, not just random bits.

 
Using this syntax, is it possible to call create_resources before and after a class declaration?



A create_resources() call can appear almost anywhere in any of your manifests, though there are many places in which it is probably not useful.  Again, however, the issue is not with the create_resources() call itself, but rather with the resources declared via that mechanism.  Denmat has offered you one possible solution, which has the advantage of not requiring any modification to the resources being declared (provided that their data did not already specify any tag).  Another alternative might be to modify the webapps::deploy_files definition to declare the dependency directly, such as via a "require 'apache'" statement.


John

Vishwa Kumba

unread,
Apr 1, 2014, 6:06:00 PM4/1/14
to puppet...@googlegroups.com
thank you,
  I found both your replies very useful. 
Reply all
Reply to author
Forward
0 new messages