How to manage one line in a file by puppet

3,053 views
Skip to first unread message

Andreas Hilboll

unread,
Jan 4, 2013, 12:46:34 PM1/4/13
to Puppet Users
Hi,

I want to write a puppet module for xen on Debian. This module will need
to manage one line in the file /etc/default/grub, namely the line
starting with "GRUB_CMDLINE_XEN=". Currently I want to leave the rest of
the file untouched.

Which would be the best way to do this?

I see two options:

a) Do some `sed` magic on the file in a `exec` call. Downside: puppet
won't notice when the line gets manually changed.

b) Have some support for sections inside files, like this:

[... part of file untouched by puppet ...]
###
# BEGIN MANAGED BY PUPPET: IDENTIFIEROFPUPPETRESOURCE
###
GRUB_CMDLINE_XEN='my options'
###
# END MANAGED BY PUPPET: IDENTIFIEROFPUPPETRESOURCE
###
[... rest of file untouched by puppet ...]

Is there support for something like this?

Cheers, Andreas.

Stephen Jahl

unread,
Jan 4, 2013, 2:06:11 PM1/4/13
to puppet...@googlegroups.com
> Hi,
>
> I want to write a puppet module for xen on Debian. This module will need
> to manage one line in the file /etc/default/grub, namely the line
> starting with "GRUB_CMDLINE_XEN=". Currently I want to leave the rest of
> the file untouched.
>
> Which would be the best way to do this?
>

Would the file_line resource from the puppetlabs stdlib do what you
want?

http://puppetlabs.com/blog/module-of-the-week-puppetlabsstdlib-puppet-labs-standard-library/

-Steve

Roman Shaposhnik

unread,
Jan 4, 2013, 2:06:19 PM1/4/13
to puppet...@googlegroups.com
Hi!

On Fri, Jan 4, 2013 at 9:46 AM, Andreas Hilboll <li...@hilboll.de> wrote:
> Hi,
>
> I want to write a puppet module for xen on Debian. This module will need
> to manage one line in the file /etc/default/grub, namely the line
> starting with "GRUB_CMDLINE_XEN=". Currently I want to leave the rest of
> the file untouched.
>
> Which would be the best way to do this?
>
> I see two options:

There's an extra option involving augeas that may work for you:
http://projects.puppetlabs.com/projects/1/wiki/puppet_augeas

Thanks,
Roman.

Dan White

unread,
Jan 4, 2013, 2:39:55 PM1/4/13
to puppet...@googlegroups.com
http://docs.puppetlabs.com/references/latest/type.html#augeas

http://forge.puppetlabs.com/puppetlabs/stdlib (file_line with match parameter)


“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
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.

Jerald Sheets

unread,
Jan 4, 2013, 1:57:27 PM1/4/13
to puppet...@googlegroups.com
I'm doing this with the augeas piece like so:

augeas { 'make_grub_verbose':
context => '/files/etc/grub.conf',
changes => [
'rm hiddenmenu',
'rm splashimage',
],
}

You should be able to use those features as you like.


--Jerald

Andreas Hilboll

unread,
Jan 4, 2013, 4:34:59 PM1/4/13
to puppet...@googlegroups.com, Stephen Jahl
Thanks guys, you're amazing :) While augeas looks like a powerful tool,
I went for the quick'n'easy file_line resource, with a match parameter
to ensure the parameter isn't set multiple times.

Cheers, have a nice weekend!
Andreas.
Reply all
Reply to author
Forward
0 new messages