ordering or chaining for generate() function

110 views
Skip to first unread message

psychobyte

unread,
Apr 24, 2012, 4:53:04 PM4/24/12
to puppet...@googlegroups.com
Hi,

 I need to run a the generate() function (server side) in order to populate a data file for one of my modules.  Is there a way to ensure that the generate function is
run before a config file is created (the contents of the file doesn't come directly from generate()).

Right now I'm getting around this by creating a bogus File resource and chaining that before I write a config file.

===============================
  file { "mp_volumes.yaml":
    ensure  => 'present',
    path    => '/tmp/cmpllnt_vol.out',
    content => generate('/usr/bin/myscript'),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
  }

  # Make sure mp_volumes.yaml is up to date before we create conf file
  File['mp_volumes.yaml']->File['conffile']
===============================

Is there a  more appropriate way of doing this?

Thanks,


Luke Bigum

unread,
Apr 25, 2012, 3:49:06 AM4/25/12
to puppet...@googlegroups.com, psychobyte
You might be able to do something like this (untested):

$blackhole_variable = generate('/usr/bin/myscript')

file { "conffile":
...
}

> --
> 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/-/5OeG7J97VsQJ.
> 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.


--
Luke Bigum

Information Systems
Ph: +44 (0) 20 3192 2520
luke....@lmax.com | http://www.lmax.com
LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN


FX and CFDs are leveraged products that can result in losses exceeding
your deposit. They are not suitable for everyone so please ensure you
fully understand the risks involved. The information in this email is not
directed at residents of the United States of America or any other
jurisdiction where trading in CFDs and/or FX is restricted or prohibited
by local laws or regulations.

The information in this email and any attachment is confidential and is
intended only for the named recipient(s). The email may not be disclosed
or used by any person other than the addressee, nor may it be copied in
any way. If you are not the intended recipient please notify the sender
immediately and delete any copies of this message. Any unauthorised
copying, disclosure or distribution of the material in this e-mail is
strictly forbidden.

LMAX operates a multilateral trading facility. Authorised and regulated
by the Financial Services Authority (firm registration number 509778) and
is registered in England and Wales (number 06505809).
Our registered address is Yellow Building, 1A Nicholas Road, London, W11
4AN.

jcbollinger

unread,
Apr 25, 2012, 9:07:05 AM4/25/12
to Puppet Users


On Apr 24, 3:53 pm, psychobyte <psychob...@gmail.com> wrote:
>  I need to run a the generate() function (server side) in order to populate
> a data file for one of my modules.  Is there a way to ensure that the
> generate function is
> run before a config file is created (the contents of the file doesn't come
> directly from generate()).


So the script run via generate() has some kind of side effect on the
master that later generation of the config file relies on? What a
terrible strategy. If you explain your problem in more detail then it
is likely that we can suggest a superior alternative.


John

Krzysztof Wilczynski

unread,
Apr 25, 2012, 9:50:52 AM4/25/12
to puppet...@googlegroups.com
Hi,

Am I right in thinking that something like that has place. On the Master:

generate() -> template() and/or "static file" -> /config/file/on/the/client

Then, if /config/file/on/the/client exists, you do not use generate(), yet when on the contrary, then you have to fire generate() first to generate content for said client-side configuration file?

KW

psychobyte

unread,
Apr 25, 2012, 12:49:03 PM4/25/12
to puppet...@googlegroups.com
Essentially, yeah.

we have a data file that needs updating on the server.  This is done through a custom script. i want to use generate() to run that script server side
 before we re-create the config files via puppet.  I want to guarantee that the generate function runs before any file resources.

Thanks.

psychobyte

unread,
Apr 25, 2012, 12:50:58 PM4/25/12
to puppet...@googlegroups.com
yes.  I'm running a server side script that creates some data used to update a client-side config file.

Krzysztof Wilczynski

unread,
Apr 25, 2012, 3:48:54 PM4/25/12
to puppet...@googlegroups.com
Hi,

On Wednesday, April 25, 2012 5:49:03 PM UTC+1, psychobyte wrote:
Essentially, yeah.
[...]
I want to guarantee that the generate function runs before any file resources.

In such case, look at stages, perhaps it will help. Other than that, if you want to make sure that said configuration file is not present on the client side and only then run generate, you could have a fact (I can help writing one) that yields a boolean if the configuration file exists or not and then use this value in an if-statement where you'd run generate() function conditionally.

KW

jcbollinger

unread,
Apr 26, 2012, 9:16:09 AM4/26/12
to Puppet Users


On Apr 25, 11:49 am, psychobyte <psychob...@gmail.com> wrote:
> Essentially, yeah.
>
> we have a data file that needs updating on the server.  This is done
> through a custom script. i want to use generate() to run that script server
> side
>  before we re-create the config files via puppet.  I want to guarantee that
> the generate function runs before any file resources.


That doesn't make sense to me. Is the data file you are trying to
generate specific to the node you want to configure?

If not, then why do you need to (re)generate it every time a node
requests a catalog?

If so, then why can't you incorporate the data generation directly
into the process of generating the target config file? Alternatively,
why is it preferable to generate the node-specific data file on the
server instead of on the node?

If you insist on continuing with this unwise approach, then you need
to understand that Puppet's resource relationships (and thus also run
stages) influence only the order in which resources are applied to the
node, not the order in which related operations are performed on the
master. Your best bet is Luke's suggestion, which is basically to
invoke generate() in the same class and above your declaration of
File['conffile']. But really, think again.


John
Reply all
Reply to author
Forward
0 new messages