Struggling with syntax

503 views
Skip to first unread message

ScubaDude

unread,
Jul 23, 2010, 8:22:13 AM7/23/10
to Puppet Users
Can someone point me in the right direction, I've got two "source"
files one 32bit, on 64bit
I've got it to work using the ternary operator but get syntax errors
if I try to use a case:

Works:

class audit {

package {
"audit":
ensure => present,
name => $operatingsystem ? {
default => "auditd",
},
}

file {
"auditd.conf":
owner => "root",
group => "root",
mode => "640",
require => Package["audit"],
path => $operatingsystem ? {
default => "/etc/auditd.conf",
},
source => "puppet://$server/modules/audit/
auditd.conf",
}

file {
"audit.rules":
owner => "root",
group => "root",
mode => "600",
path => $operatingsystem ? {
default => "/etc/audit.rules",
},
source => $hardwaremodel ? {
"x86_64" => "puppet://$server/modules/
audit/audit.rules.64",
default => "puppet://$server/modules/
audit/audit.rules.32",
},
}

service {
"audit":
enable => "true",
ensure => "running",
hasstatus => "true",
require => File["auditd.conf", "audit.rules"],
subscribe => File["auditd.conf", "audit.rules"],
name => $operatingsystem ? {
default => "auditd",
},
}
}

Syntax Error:

Jul 23 13:20:43 <master> puppetmasterd[14197]: Syntax error at 'case';
expected '}' at /etc/puppet/modules/audit/manifests/init.pp:32 on node
<client>
Jul 23 13:20:43 <master> puppetmasterd[14197]: Syntax error at 'case';
expected '}' at /etc/puppet/modules/audit/manifests/init.pp:32 on node
<client>

class audit {

package {
"audit":
ensure => present,
name => $operatingsystem ? {
default => "auditd",
},
}

file {
"auditd.conf":
owner => "root",
group => "root",
mode => "640",
require => Package["audit"],
path => $operatingsystem ? {
default => "/etc/auditd.conf",
},
source => "puppet://$server/modules/audit/
auditd.conf",
}

file {
"audit.rules":
owner => "root",
group => "root",
mode => "600",
path => $operatingsystem ? {
default => "/etc/audit.rules",
},
case $hardwaremodel {
"x86_64": { source => "puppet://
$server/modules/audit/audit.rules.64" }
default: { source => "puppet://
$server/modules/audit/audit.rules.32" }
},
}

service {
"audit":
enable => "true",
ensure => "running",
hasstatus => "true",
require => File["auditd.conf", "audit.rules"],
subscribe => File["auditd.conf", "audit.rules"],
name => $operatingsystem ? {
default => "auditd",
},
}
}

Tony G.

unread,
Jul 23, 2010, 12:08:06 PM7/23/10
to puppet...@googlegroups.com
You might want to add the case statement out of the file resource and assign to a variable for the source:

case $hardwaremodel {
     "x86_64": { $hw_source = "puppet://$server/modules/audit/audit.rules.64" }
      default: { $hw_source = "puppet://$server/modules/audit/audit.rules.32" }
  }

Then insinde the file resource only add the variable to the source:
source => $hw_source,

Seems like the parser does not allow case statements in the attributes of the resources.

--
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.




--
Tony
http://blog.tonyskapunk.net

Jeff McCune

unread,
Jul 23, 2010, 12:29:31 PM7/23/10
to puppet...@googlegroups.com
On Fri, Jul 23, 2010 at 9:08 AM, Tony G. <ton...@gmail.com> wrote:
>
> Seems like the parser does not allow case statements in the attributes of
> the resources.

This is correct, case statements must be outside of resource
statements. You could use the selector in-statement though.

file { "/tmp/foo":


source => $hardwaremodel ? {
"x86_64" => "puppet://$server/modules/audit/audit.rules.64",
default => "puppet://$server/modules/audit/audit.rules.32"
}
}

Cheers,
--
Jeff McCune
http://www.puppetlabs.com/

devzero2000

unread,
Jul 23, 2010, 11:53:12 AM7/23/10
to puppet...@googlegroups.com
On Fri, Jul 23, 2010 at 2:22 PM, ScubaDude <brett...@googlemail.com> wrote:
> Can someone point me in the right direction, I've got two "source"
> files one 32bit, on 64bit
Probably more elegant to use a ERB template only

David Schmitt

unread,
Jul 26, 2010, 3:20:32 AM7/26/10
to puppet...@googlegroups.com
On 7/23/2010 2:22 PM, ScubaDude wrote:
> file {
> "audit.rules":
> owner => "root",
> group => "root",
> mode => "600",
> path => $operatingsystem ? {
> default => "/etc/audit.rules",
> },
> case $hardwaremodel {
> "x86_64": { source => "puppet://
> $server/modules/audit/audit.rules.64" }
> default: { source => "puppet://
> $server/modules/audit/audit.rules.32" }
> },
> }

Write instead:

file {
"audit.rules":
owner => "root",
group => "root",
mode => "600",
path => $operatingsystem ? {
default => "/etc/audit.rules",
},
}

case $hardwaremodel {
"x86_64": { File["audit.rules"] { source =>
"puppet:///modules/audit/audit.rules.64" } },
default: { File["audit.rules"] { source =>
"puppet:///modules/audit/audit.rules.32" } },
}


Best Regards, David
--
dasz.at OG Tel: +43 (0)664 2602670 Web: http://dasz.at
Klosterneuburg UID: ATU64260999

FB-Nr.: FN 309285 g FB-Gericht: LG Korneuburg

Andrew Forgue

unread,
Jul 26, 2010, 11:57:16 AM7/26/10
to Puppet Users


On Jul 26, 12:20 am, David Schmitt <da...@dasz.at> wrote:
>
> Write instead:
>
> file {
>         "audit.rules":
>                 owner =>  "root",
>                 group =>  "root",
>                 mode  =>  "600",
>                 path  =>  $operatingsystem ? {
>                         default =>  "/etc/audit.rules",
>                 },
>
> }
>
> case $hardwaremodel {
>         "x86_64": { File["audit.rules"] { source =>
> "puppet:///modules/audit/audit.rules.64" } },
>         default:  { File["audit.rules"] { source =>
> "puppet:///modules/audit/audit.rules.32" } },
>
> }
>

I have to say I don't like this at all. I think a far more clearer
definition would be like this:

file {
        "audit.rules":
                owner =>  "root",
                group =>  "root",
                mode  =>  "600",
                path  =>  "/etc/audit.rules,
source => [
"puppet:///modules/audit/audit.rules.
$hardwaremodel",
"puppet:///modules/audit/audit.rules"
]
}

Then you just create a audit/files/audit.rules.x86_64 and anything
else will fall through to audit.rules.

David Schmitt

unread,
Jul 27, 2010, 10:32:56 AM7/27/10
to puppet...@googlegroups.com
+1, although it just works for the source parameter.

Erinn Looney-Triggs

unread,
Jul 27, 2010, 4:58:00 PM7/27/10
to Puppet Users
An option I like is a source like this:
source => "puppet://$servername/modules/audit/$architecture/
audit.rules"

Place your audit.rules in x86_64 and whatever 32-bit is (sorry don't
have any of those).

-Erinn

ScubaDude

unread,
Jul 30, 2010, 8:24:56 AM7/30/10
to Puppet Users
Thanks for the responses!

I'll try some of these out and post what I end up with.

devzero, have you looked at how completely different the requirements
are for 32bit and 64bit in audit.rules? Using an erb would be a
nightmare!

ScubaDude

unread,
Jul 30, 2010, 8:40:19 AM7/30/10
to Puppet Users
After a brief deliberation, it was actually a toss up between Andrew
Forgue and Erinn Loony-Trigss's suggestions.

I opted for Andrew's solution as in this case it seemed the neatest,
although it was a very close thing.
I'm sure that using an architecture directory would be the more
elegant solution in some cases though.

To everyone else, thank you for shedding some light on how puppet
deals with case statements as I'm sure I'll be needing those in the
future.

Thanks again for your help.
Reply all
Reply to author
Forward
0 new messages