File() or Exec() temporary override?

86 views
Skip to first unread message

Martin Langhoff

unread,
Nov 5, 2013, 10:11:38 AM11/5/13
to puppet...@googlegroups.com
Hi Puppeteers,

When you have complex/rich classes, and large numbers of machines/VMs,
sometimes there is a machine that needs a temporary override on a
file.

Is there a way to say something like... ?

node 'fqdn' { # I work for RL :-)
include rl_users
include rl_base
include rl_webserver # defines /etc/httpd/conf.d/foo.conf
ignore File['/etc/httpd/conf.d/foo.conf']
}

or something conceptually equivalent?

I know of a couple inelegant options: I can disable puppet on that VM
for the duration, or comment out the relevant class.

A more precise override/ignore is of course better, as other
components of the configuration are still applied correctly.



m
--
martin....@gmail.com
- ask interesting questions
- don't get distracted with shiny stuff - working code first
~ http://docs.moodle.org/en/User:Martin_Langhoff

jcbollinger

unread,
Nov 6, 2013, 9:55:46 AM11/6/13
to puppet...@googlegroups.com


On Tuesday, November 5, 2013 9:11:38 AM UTC-6, Martin Langhoff wrote:
Hi Puppeteers,

When you have complex/rich classes, and large numbers of machines/VMs,
sometimes there is a machine that needs a temporary override on a
file.

Is there a way to say something like... ?

  node 'fqdn' { # I work for RL :-)
      include rl_users
      include rl_base
      include rl_webserver # defines /etc/httpd/conf.d/foo.conf
      ignore File['/etc/httpd/conf.d/foo.conf']
  }

or something conceptually equivalent?

I know of a couple inelegant options: I can disable puppet on that VM
for the duration, or comment out the relevant class.

A more precise override/ignore is of course better, as other
components of the configuration are still applied correctly.



You could consider just shutting down or deactivating the puppet agent on the affected machine for the duration of the override.  For example, run

puppet agent --disable

there and afterward run

puppet agent --enable

.  If that's not viable, then something close to the idea you proposed should be possible:

node 'fqdn' { # I work for RL :-)
  include rl_users
  include rl_base
  include rl_webserver
  File<| title == '/etc/httpd/conf.d/foo.conf' |> {
    ensure => 'present',
    content => undef
    # override other properties to undef (no quotes)
    # as needed.
  }
}


John

Martin Langhoff

unread,
Nov 6, 2013, 10:01:17 AM11/6/13
to puppet...@googlegroups.com
On Wed, Nov 6, 2013 at 9:55 AM, jcbollinger <John.Bo...@stjude.org> wrote:
> . If that's not viable, then something close to the idea you proposed
> should be possible:

By "should be possible, do you mean that you know or think that Puppet
supports it?

> node 'fqdn' { # I work for RL :-)
> include rl_users
> include rl_base
> include rl_webserver
> File<| title == '/etc/httpd/conf.d/foo.conf' |> {
> ensure => 'present',
> content => undef
> # override other properties to undef (no quotes)
> # as needed.
> }
> }

Does this syntax work, and does it elegantly override any other File
stanzas that point to that file path? Does content=>undef override
'source' or do I need to also say source->undef ?

If that actually works, what other types support this trick?

thanks,

jcbollinger

unread,
Nov 7, 2013, 9:04:28 AM11/7/13
to puppet...@googlegroups.com


On Wednesday, November 6, 2013 9:01:17 AM UTC-6, Martin Langhoff wrote:
On Wed, Nov 6, 2013 at 9:55 AM, jcbollinger <John.Bo...@stjude.org> wrote:
> .  If that's not viable, then something close to the idea you proposed
> should be possible:

By "should be possible, do you mean that you know or think that Puppet
supports it?



I mean I believe the code I presented will accomplish your objective.

 
> node 'fqdn' { # I work for RL :-)
>   include rl_users
>   include rl_base
>   include rl_webserver
>   File<| title == '/etc/httpd/conf.d/foo.conf' |> {
>     ensure => 'present',
>     content => undef
>     # override other properties to undef (no quotes)
>     # as needed.
>   }
> }

Does this syntax work, and does it elegantly override any other File
stanzas that point to that file path? Does content=>undef override
'source' or do I need to also say source->undef ?



There can be only one declaration for any resource.  There can be multiple overrides, but the result is undefined (evaluation-order dependent, to be precise) if any two override the same property of the same underlying resource.

 
If that actually works, what other types support this trick?


It is an application of general-purpose features of Puppet DSL, mainly resource collectors (http://docs.puppetlabs.com/puppet/3/reference/lang_collectors.html) and overriding / "amending" properties of declared resources (http://docs.puppetlabs.com/puppet/2.7/reference/lang_resources.html#adding-or-modifying-attributes).  Use of the special 'undef' value in such context is documented in the related section on amending resource properties via class inheritance (http://docs.puppetlabs.com/puppet/3/reference/lang_classes.html#inheritance).

In other words, that approach should work with all resource types, including defined types.  It does not work with classes, however, even though classes can be declared via a syntax that looks like a resource declaration.  For this and other reasons, it is best to take the view that classes are not resources.


John

Reply all
Reply to author
Forward
0 new messages