What you've coded seems workable, aside from two issues. 1) the errant
semicolon at the end (while that may work to 'end' the resource defaults,
its bad style when you don't have defaults). 2) exec resource titles need
to be unique if the defined type is used twice; adding the $name value of
the defined type should provide uniqueness. This will not show up in your
example where the type is only used once, but best to plan for long haul.

However, we don't know what you are trying to accomplish. Your first
conditional should probably be an and, because otherwise the conditional
will always be true ($env will always not be one of those values). The case
selectors have no default, do you need one? Should you be using a global
variable vs passing the value to a type parameter? Probably the latter. If
you explain your goal, then we can offer specific suggestions on how to
make the code accomplish it.

On Mon, May 1, 2017 at 7:43 PM Samir Gahirwal <[email protected]>
wrote:

> Hi,
>
> I am very new to puppet and writing my first class :) Please pardon me for
> asking basic question
>
> I am trying to write module to run install script. Can someone help me
> with syntax or suggest better way to code following
>
> define install-package {
> if ( $env != 'test' or $env != 'qa') {
>             case $::package_type {
>                 'abc': {
>                     $variable = '123'
>                       }
>                 'xyz': {
>                     $variable = '345'
>                       }
>    exec {"run_my_script":
>           source => "puppet:///modules/mymodule/resources/myinstall
> script.sh",
>           command => 'sh myscript.sh $variable'
>         }
>
>              }
> else {
>             case $::package_type {
>                 'abc': {
>                     $variable = '567'
>                       }
>                 'xyz': {
>                     $variable = '789'
>                       }
>              }
>    exec {"run_my_script":
>           source => "puppet:///modules/mymodule/resources/myinstall
> script.sh",
>           command => 'sh myscript.sh $variable'
>         }
> }
>
> class mymodule::software {
>     $package_type = unique([jdk,apache,tomcat])
>     install-package { $package_type:; }
> }
>
> I am deriving env variable from host name.
>
> Let me know if you need additional details.
>
> Thanks!
> --SamirG
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/ecb68180-af56-4d36-a555-236a69efea50%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/ecb68180-af56-4d36-a555-236a69efea50%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Rob Nelson

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAC76iT856cgrr%3DBNgpi3twGWYAyCAydO8bNHK5to9ToXoWrUNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to