Let me know if you need more details. 

Thanks again!!


Hi Rob, 

Thanks for your response. Please find answers inline 

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

Purpose of this module is to generate java keystores. I want to use 
different password for our test end and prod env for those certificates. 
The env value I am deriving from "$env = vd_get($::__vd, 'env')" and o/p 
could be test/qa/prod/colo. So test/qa should be true for first case. Else 
use other passwords. 

The case selectors have no default, do you need one?
Thats great, actually I was looking for way to avoid using default. 

Here is exact code snippet. 

define certificate-generator {
        user => root,
        group => root,
       
        if ( $env != 'test' or $env != 'qa') {
            case $::target_cert_type {
                'type1': {
                    $password = '123'
                      }
                'type2': {
                    $password = '345'
                      }
                default: {
                    fail("No password defined")
                      }
            }
         exec { "certificate-generator":
              command => 'sh certgen.sh',
              path    => '/bin/bash',
              logoutput => true,
              onlyif =>  "test ! -f ${cert_basedir}/${host}.jks"
              source => "puppet:///modules/mymodule/certgen/certgen.sh 
$password"
              }
         }
         else {
              case $::target_cert_type {
                'type1': {
                    $password = '567'
                      }
                'type2': {
                    $password = '789'
                      }
                default: {
                    fail("No password defined ")
                      }    
         exec { "certificate-generator":
              command => 'sh certgen.sh',
              path    => '/bin/bash',
              logoutput => true,
              onlyif =>  "test ! -f ${cert_basedir}/${host}.jks"
              source => "puppet:///modules/mymodule/certgen/certgen.sh 
$password"
              }    
         }

class javakeystore::certgen{
    $env = vd_get($::__vd, 'env')
    $cert_type = vd_get($::__vd, 'certtype')
    $target_cert_type = unique([$cert_type])
    certificate-generator { $target_cert_type:; }
}






On Monday, May 1, 2017 at 8:02:05 PM UTC-7, Rob Nelson wrote:
>
> 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 <samir.g...@gmail.com 
> <javascript:>> 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 puppet-users...@googlegroups.com <javascript:>.
>> 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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/277b8ea6-3dea-404f-97ab-4b4d3b9565e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to