This is inefficient since all of the if statements will be evaluated
even if a previous if statement triggered. You can change that by using:
if $ldap_conf_file =~ /aaa/ and $operatingsystem == xxx {
file { '/etc/ssh/sshd_config': ensure => present }
}
elsif xxx {
file { '/etc/ssh/sshd_config': ensure => present }
}
# etc. etc.
else {
file { '/etc/ssh/sshd_config': ensure => present }
}
It is also inefficient since both the regexp match is repeated in every
case. You can nest the if statements, or you can use (nested) case
statements:
case $ldap_conf_file {
/aaa/ : {
case $operatingsystem {
aix: {
file { '/etc/ssh/sshd_config': ensure => present }
}
redhat: {
file { '/etc/ssh/sshd_config': ensure => present }
}
# etc
}
/bbb/ : {
case $operatingsystem {
aix: {
file { '/etc/ssh/sshd_config': ensure => present }
}
redhat: {
file { '/etc/ssh/sshd_config': ensure => present }
}
# etc
}
/ccc/ : {
case $operatingsystem {
aix: {
file { '/etc/ssh/sshd_config': ensure => present }
}
redhat: {
file { '/etc/ssh/sshd_config': ensure => present }
}
# etc
}
default: {
# what to do when not matched
)
}
Or, use case statementss as above, but set a variable instead, and then
have the file resource at the end. Since you are setting a variable, you
can use the selector expression instead of a case - e.g:
$sshd_config_file = $operatingsystem ? {
aix => '/etc/sshd/sshd_config',
redhat => '. . .',
# etc
}
And at the end do like this:
file { "$sshd_config_file": ensure => present }
Hope that helps
Regards
- henrik