Hello All,
I''m not able to do an if/then statement within a file resource
declaration. I''m basically trying to distinguish between OS release,
so
that I can assign an appropriate template. This is what I have:
class basic_dev::files {
file { "/etc/sudoers":
owner => root,
group => root,
mode => 0440,
if $operatingsystemrelease <= 5.4 then {
content => template("system/sudoers_V54.erb")},
else {
content => template("system/sudoers.erb")},
backup => ".bak"
}
For some reason is not working. I keep on getting error: "Could not
retrieve catalog from remote server: Error 400 on SERVER: Syntax error at
''if''; expected ''}'' "
Any ideas?
Thanks,
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Mark Stanislav
2010-Dec-17 20:57 UTC
Re: [Puppet Users] if then statement within file resource
What about just doing:
if ($operatingsystemrelease <= 5.4) {
$sudo_template = "system/sudoers_V54.erb"
} else {
$sudo_template = "system/sudoers.erb"
}
class basic_dev::files {
file { "/etc/sudoers":
owner => root,
group => root,
mode => 0440,
content => template($sudo_template),
backup => ".bak"
}
Seems legit at least ;)
On Dec 17, 2010, at 3:51 PM, CraftyTech wrote:
> Hello All,
>
> I''m not able to do an if/then statement within a file
resource declaration. I''m basically trying to distinguish between OS
release, so that I can assign an appropriate template. This is what I have:
>
> class basic_dev::files {
> file { "/etc/sudoers":
> owner => root,
> group => root,
> mode => 0440,
> if $operatingsystemrelease <= 5.4 then {
> content => template("system/sudoers_V54.erb")},
> else {
> content => template("system/sudoers.erb")},
> backup => ".bak"
> }
> For some reason is not working. I keep on getting error: "Could not
retrieve catalog from remote server: Error 400 on SERVER: Syntax error at
''if''; expected ''}'' "
>
> Any ideas?
>
> Thanks,
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
> To post to this group, send email to puppet-users@googlegroups.com.
> To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Disconnect
2010-Dec-17 20:58 UTC
Re: [Puppet Users] if then statement within file resource
You can do it magically with source, not sure about template though.
source =>
["puppet:///system/sudoers_$operatingsysstemrelease","puppet:///system/sudoers"]
(it will look for them in order. We have several that go hostname,
$lsbdistcodename, generic.)
If it doesn''t work for template, you can do it the hard way:
if $operatingsystemrelease <= 5.4 {
file { "/etc/sudoers":....etc
} else {
file { "/etc/sudoers":.....
}
On Fri, Dec 17, 2010 at 3:51 PM, CraftyTech <hmmedina@gmail.com> wrote:
> Hello All,
>
> I''m not able to do an if/then statement within a file
resource
> declaration. I''m basically trying to distinguish between OS
release, so
> that I can assign an appropriate template. This is what I have:
>
> class basic_dev::files {
> file { "/etc/sudoers":
> owner => root,
> group => root,
> mode => 0440,
> if $operatingsystemrelease <= 5.4 then {
> content => template("system/sudoers_V54.erb")},
> else {
> content => template("system/sudoers.erb")},
> backup => ".bak"
> }
> For some reason is not working. I keep on getting error: "Could not
> retrieve catalog from remote server: Error 400 on SERVER: Syntax error at
> ''if''; expected ''}'' "
>
> Any ideas?
>
> Thanks,
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to puppet-users@googlegroups.com.
> To unsubscribe from this group, send email to
>
puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Eric Sorenson
2010-Dec-17 21:04 UTC
Re: [Puppet Users] if then statement within file resource
On Dec 17, 2010, at 12:51 PM, CraftyTech wrote:> I''m not able to do an if/then statement within a file resource declaration. I''m basically trying to distinguish between OS release, so that I can assign an appropriate template. This is what I have:Yes the language tutorial on conditionals explains this. You can use a selector inside the resource or the if/else syntax outside the resource to set a variable. Selector is less nice because you can''t do the numeric comparison, you have to fake it with a regexp. ie. file {"/etc/sudoers": content => $operatingsystemrelease ? /^5.[01234]/ => template("system/sudoers_V54.erb"), default => template("system/sudeors.erb") } or as other people described, move your if/else outside the resource to set a local variable that you then expand. - Eric Sorenson - N37 17.255 W121 55.738 - http://twitter.com/ahpook - -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
CraftyTech
2010-Dec-17 21:09 UTC
Re: [Puppet Users] if then statement within file resource
That worked out.... Wondering why it didn''t inside the file resource... but it the workaround is certainly is "legit" enough.... Thanks, -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
svrsvr91@gmail.com
2013-Sep-06 00:04 UTC
Re: [Puppet Users] if then statement within file resource
Hi
i am trying the same it is not working can u explain me how it worked
file { "/etc/inittab":
owner => root,
group => root,
mode => 0644,
if $manufacturer=IBM {
content => template("${module_name}/ibm.inittab.erb")},
else {
content => template("${module_name}/sun.inittab.erb")},
backup => ".bak"
On Friday, December 17, 2010 1:09:52 PM UTC-8, CraftyTech
wrote:>
> That worked out.... Wondering why it didn''t inside the file
resource...
> but it the workaround is certainly is "legit" enough....
>
> Thanks,
>
>
>
--
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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.
Frederiko Costa
2013-Sep-06 00:57 UTC
Re: [Puppet Users] if then statement within file resource
Hi,
I believe in that case you should use selectors to make it work.
http://docs.puppetlabs.com/puppet/2.7/reference/lang_conditional.html#selectors
Or you can use the ''if'' outside the file resource. Something
like this:
$template_name = $manufacter ? {
''ibm'' => "${module_name}/ibm.inittab.erb",
default => "${module_name}/sun.inittab.erb",
}
Then your file resource
file { "/etc/inittab":
owner => root,
group => root,
mode => 0644,
content => template($template_name),
backup => ".bak",
}
It''s also best practice to use selectors outside resource block per
http://puppet-lint.com/checks/selector_inside_resource/
I hope it helps.
-frederiko
On Thu, Sep 5, 2013 at 5:04 PM, <svrsvr91@gmail.com> wrote:
> Hi
> i am trying the same it is not working can u explain me how it worked
>
> file { "/etc/inittab":
> owner => root,
> group => root,
> mode => 0644,
> if $manufacturer=IBM {
> content =>
template("${module_name}/ibm.inittab.erb")},
> else {
> content =>
template("${module_name}/sun.inittab.erb")},
> backup => ".bak"
>
>
> On Friday, December 17, 2010 1:09:52 PM UTC-8, CraftyTech wrote:
>>
>> That worked out.... Wondering why it didn''t inside the file
resource...
>> but it the workaround is certainly is "legit" enough....
>>
>> Thanks,
>>
>>
>> --
> 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 post to this group, send email to puppet-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/puppet-users.
> 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 post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.