if statement not being parsed when trying to select omit the ensure parameter from a resource.

11 views
Skip to first unread message

Thom Luxford

unread,
Aug 2, 2014, 12:19:35 AM8/2/14
to puppe...@googlegroups.com
The intention is for the the service running state after boot to be optionally handled by puppet. Omitting the ensure parameter does this, but why can't I add it when I need it like this?
  
service { "$my_module::params::myServiceName":
    if $::my_service_ensure_running != 'undef' {
      ensure  => "$my_module::my_service_ensure_running",
    }
    enable  => 'true',
    require => [ Package["$oscar_legacy::params::mysqlPackageName"], File["/etc/mysql/conf.d/mysqld_oscar_dbs.cnf"] ],
  }

puppet parser validate {}
complains as so:

Error: Could not parse for environment production: Syntax error at '::my_service_ensure_running'; expected '}' at /home/oscara/git/puppetmaster/modules/my_module/manifests/init.pp:154

David Schmitt

unread,
Aug 4, 2014, 8:43:44 AM8/4/14
to puppe...@googlegroups.com
the "if" is a statement that cannot be used inside a resource definition.

Write it like this:

service { "$my_module::params::myServiceName":
enable => 'true',
require => [ ...]
}

if $::my_service_ensure_running != 'undef' {
Service["$my_module::params::myServiceName"]{
ensure => $::my_service_ensure_running,
}
}

See the Puppet Language Reference
(http://docs.puppetlabs.com/puppet/latest/reference/lang_conditional.html)
for details.


Regards, David

--
* Always looking for people I can help with awesome projects *
G+: https://plus.google.com/+DavidSchmitt
Blog: http://club.black.co.at/log/
LinkedIn: http://at.linkedin.com/in/davidschmitt
Reply all
Reply to author
Forward
0 new messages