FAQ
Hello,

I apologize in advance if this question is redundant.

I'm using puppet version 2.7.11 (because that's what Ubuntu 12.04 LTS has
to offer) and I'd like to override a class default parameter with 'undef'.
  For example, the puppetlabs 'apache' module (version 0.10.0) sets 'ensure
=> running' for service 'apache' by default. I do not what puppet to
attempt starting or stopping apache, so I'm trying the following (which
does not work):

   class {
     'apache': service_ensure => undef;
   }

The above gives me the default 'ensure => running' for the 'apache'
service. Any idea how I can express 'ensure => undef' when declaring the
apache class in my manifest?

Could suppose I could always hack the 'apache' module, but would prefer not
to.

Thanks,
Jeffrey

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/af002012-5084-48e8-9f61-9fac2b64889e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • David Arroyo at Jan 11, 2014 at 3:49 pm
    Hi Jeffrey,

    You cannot override the default parameter to be undef, but you can
    override the service resource's behaviour with a resource collector[0].
    It's less than ideal because you have to know the name of the service,
    but something like this:

      class{'apache':}
      Service <|title == 'apache'|> {
        noop => true,
      }

    should work. You can alternatively search by the class tag, but be sure
    it has no unintended side effects.

    Cheers,
    David

    [0]:
    http://docs.puppetlabs.com/puppet/latest/reference/lang_collectors.html
    On Fri, Jan 10, 2014 at 6:04 PM, Jeffrey Lewis wrote:
    Hello,

    I apologize in advance if this question is redundant.

    I'm using puppet version 2.7.11 (because that's what Ubuntu 12.04 LTS
    has to offer) and I'd like to override a class default parameter with
    'undef'.  For example, the puppetlabs 'apache' module (version
    0.10.0) sets 'ensure => running' for service 'apache' by default.  I
    do not what puppet to attempt starting or stopping apache, so I'm
    trying the following (which does not work):

    class {
    'apache': service_ensure => undef;
    }

    The above gives me the default 'ensure => running' for the 'apache'
    service.  Any idea how I can express 'ensure => undef' when
    declaring the apache class in my manifest?

    Could suppose I could always hack the 'apache' module, but would
    prefer not to.

    Thanks,
    Jeffrey
    --
    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+unsubscribe@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/puppet-users/af002012-5084-48e8-9f61-9fac2b64889e%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/20140111154917.6463B120BDC%40mail.aqwari.net.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jcbollinger at Jan 13, 2014 at 2:27 pm

    On Friday, January 10, 2014 5:04:50 PM UTC-6, Jeffrey Lewis wrote:
    Hello,

    I apologize in advance if this question is redundant.

    I'm using puppet version 2.7.11 (because that's what Ubuntu 12.04 LTS has
    to offer) and I'd like to override a class default parameter with 'undef'.
    For example, the puppetlabs 'apache' module (version 0.10.0) sets 'ensure
    => running' for service 'apache' by default. I do not what puppet to
    attempt starting or stopping apache, so I'm trying the following (which
    does not work):

    class {
    'apache': service_ensure => undef;
    }

    The above gives me the default 'ensure => running' for the 'apache'
    service. Any idea how I can express 'ensure => undef' when declaring the
    apache class in my manifest?
    All class parameters must have values assigned, whether by explicit
    declaration or by default value (or by automated data binding, but that
    requires Puppet 3). Undef is not a value. In fact "not a value" is
    practically its definition. Declaring a class or resource parameter as
    undef is an explicit expression of not assigning a value. That can
    actually make a difference in the presence of declared resource-type
    defaults (e.g. File { owner => 'root', mode => 0644 } ), but what you're
    fighting with is a different kind of default -- the one assigned when there
    is no explicit value declared. That is exactly the situation you present
    by declaring the parameter undef.


    Could suppose I could always hack the 'apache' module, but would prefer
    not to.
    Check the module documentation, but it sounds like the stock version does
    not support what you want to do. David's suggestion to override
    Service['apache'] might succeed for you or it might not, as there could be
    other effects of the 'service_ensure' parameter, and the title of the
    relevant Service resource doesn't have to be 'apache'. Either way, it is
    poor form to touch module internals, such as the putative
    Service['apache'], except as module documentation supports.

    David's might still be the approach that works best for you. Personally,
    though, I would look into modifying the module appropriately, then opening
    an issue against it and contributing your solution. Perhaps you could make
    an empty value of service_ensure suppress managing the run state of the
    service.


    John

    --
    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+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/7122b1f4-655b-4bc2-9ab3-0b719de74f00%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jeffrey Lewis at Jan 13, 2014 at 7:01 pm

    On Monday, January 13, 2014 6:27:17 AM UTC-8, jcbollinger wrote:

    All class parameters must have values assigned, whether by explicit
    declaration or by default value (or by automated data binding, but that
    requires Puppet 3). Undef is not a value. In fact "not a value" is
    practically its definition. Declaring a class or resource parameter as
    undef is an explicit expression of not assigning a value.

    Right. So, setting "service_ensure => undef" is equivalent to setting
    nothing, and the module uses the default value for service_ensure (which is
    'running').


    Check the module documentation, but it sounds like the stock version does
    not support what you want to do.

    Agreed. Worse, the documentation states that setting 'service_ensure =>
    undef' should work, but that isn't the case for me, at least in puppet
    2.7.11.

    service_ensure

    Determines whether the service should be running. Can be set to 'undef'
    which is useful when you want to let the service be managed by some other
    application like pacemaker. Defaults to 'running'.

    Personally, though, I would look into modifying the module appropriately,
    then opening an issue against it and contributing your solution. Perhaps
    you could make an empty value of service_ensure suppress managing the run
    state of the service.

    I ended up using a 'selector' as a ternary operator to do just that.
      Hopefully my syntax isn't too ugly. I'll see if the puppetlabs folks can
    accept this upstream. For reference, I modified manifests/service.pp to
    look like this:

       service { 'httpd':
         ensure => $service_ensure ? {
                     '' => undef,
                     default => $service_ensure,
                   },
         name => $service_name,
         enable => $service_enable,
       }

    Thanks,
    Jefffrey

    --
    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+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/14edbaf9-3cd8-43f8-9096-ae6e5cf09ee2%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Felix Frank at Jan 20, 2014 at 1:39 am
    What I like to do in situations like this:

        service { 'httpd':
          name => $service_name,
          enable => $service_enable,
        }

        if $service_ensure {
          Service['httpd'] { ensure => $service_ensure }
        }

    It looks like an override, but it does work in the same class iff the
    respective properties (or parameters) are not yet declared.

    Cheers,
    Felix
    On 01/13/2014 08:01 PM, Jeffrey Lewis wrote:
    For reference, I modified manifests/service.pp to look like this:

    service { 'httpd':
    ensure => $service_ensure ? {
    '' => undef,
    default => $service_ensure,
    },
    name => $service_name,
    enable => $service_enable,
    }
    --
    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+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/52DC7E43.5000605%40Alumni.TU-Berlin.de.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedJan 10, '14 at 11:32p
activeJan 20, '14 at 1:39a
posts5
users4
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase