collecting resources for iteration in a template

319 views
Skip to first unread message

Jonathon Anderson

unread,
Apr 16, 2012, 4:45:57 AM4/16/12
to puppet...@googlegroups.com
I have a `sysctl::variable` defined type that creates files in `/etc/sysctl.d`.  Some operating systems (*cough*SLES10*cough*) don't read sysctl settings from `/etc/sysctl.d`, though, and expect all settings to be in a single file, `/etc/sysctl.conf`.  For such operating systems, I'd like to define the content of that file with a template that references the values of the `sysctl::variable`s.

In the Puppet DSL I can collect all fragments with language like `Sysctl::Variable<| |>`.  How can I do something similar in a template such that I can access the variable names and values?  For example:

<%
variables = magic('Sysctl::Variable<||>')
variables.each do |variable| -%>
<%= variable.name %> = <%= variable.value %>
<% end -%>

Wil Cooley

unread,
Apr 17, 2012, 1:46:33 AM4/17/12
to Puppet Users
On Apr 16, 1:45 am, Jonathon Anderson <anderbub...@gmail.com> wrote:
> I have a `sysctl::variable` defined type that creates files in
> `/etc/sysctl.d`.  Some operating systems (*cough*SLES10*cough*) don't read
> sysctl settings from `/etc/sysctl.d`, though, and expect all settings to be
> in a single file, `/etc/sysctl.conf`.  For such operating systems, I'd like
> to define the content of that file with a template that references the
> values of the `sysctl::variable`s.
>
> In the Puppet DSL I can collect all fragments with language like
> `Sysctl::Variable<| |>`.  How can I do something similar in a template such
> that I can access the variable names and values?  For example:

Have you considered instead using something like the "file fragment
pattern"? Basically, you add 'notifiy' to sysctl::variable resources
to notify an exec that rebuilds sysctl.conf from sysctl.d (basically
"cat /etc/sysctl.d/*.conf > /etc/sysctl.conf").

http://projects.puppetlabs.com/projects/puppet/wiki/Generating_a_config_file_from_fragments

(I'm not sure the special concatenation script is really necessary;
you can have the exec notify the service to reload if necessary and
the 'for' loop is unnecessary with shell wildcards. At least, that's
how we do it at work.)

Wil

Luke Bigum

unread,
Apr 17, 2012, 4:14:15 AM4/17/12
to puppet...@googlegroups.com
Just in case you haven't seen it, RIP's original concat module:
https://github.com/ripienaar/puppet-concat

It hides a lot of the concatenation implementation detail in defined
types and the temporary file fragments are stored under /var/lib/puppet/.


--
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.

Jonathon Anderson

unread,
Apr 17, 2012, 5:58:51 AM4/17/12
to puppet...@googlegroups.com
On Tuesday, April 17, 2012 8:46:33 AM UTC+3, Wil Cooley wrote:
Have you considered instead using something like the "file fragment
pattern"? Basically, you add 'notifiy' to sysctl::variable resources
to notify an exec that rebuilds sysctl.conf [...]

Yeah, that's what we're already doing.  I just dislike distributing a script to do something that, in my opinion, should be part of assembling the catalog in the first place.  It's also stateful (to the state at which the fragment is first distributed), and, thus, fragile.  (A failure rebuilding once will not be repaired on subsequent runs unless the fragments or the script change.)

Jonathon Anderson

unread,
Apr 17, 2012, 8:16:57 AM4/17/12
to puppet...@googlegroups.com
On Tuesday, April 17, 2012 11:14:15 AM UTC+3, Luke Bigum wrote:
Just in case you haven't seen it, RIP's original concat module:
https://github.com/ripienaar/puppet-concat

I hadn't seen it.  Thank you for the pointer.  Like I said, this is basically what we're doing now; but It's probably better to use that than to re-implement this for every fragment-concatenating module we have.  If I end up not being able to find a compilation-time solution, this is probably the best avenue left.

tl;dr, once again, RIP has already thought of that!

~jonathon

Reply all
Reply to author
Forward
0 new messages