Replace multiple expression with a variable in a selector

218 views
Skip to first unread message

Francisco José Bejarano

unread,
Jan 15, 2014, 6:19:22 AM1/15/14
to puppet...@googlegroups.com
Greetings to all

I have a question about the use of selectors. I am using 3.4.2

I have this selector in my code


  $testing = $::hostname ? {
    /(host1|host2|host3)/  => 'filetest',
    default                => 'file',
  }


I would like to use a variable as a multiple expression in a selector like this

$VARIABLE ='/(host1|host2|host3)/'

  $testing = $::hostname ? {
    $VARIABLE  => 'filetest',
    default    => 'file',
  }


¿Is that possible?

I've tried different ways but does not work. With quotes, without quotes, etc.. It always select the default file (file) if I put variable, but if I do not put variable (first code) it works ok and FileTest is used if hostname is in expression.

I would like to use VARIABLE in hiera to use the name of hosts (not in hard code)

¿Is that possible?

Thanks in advance :-)

Andrey Kozichev

unread,
Jan 15, 2014, 7:20:20 AM1/15/14
to puppet...@googlegroups.com
try $VARIABLE ='(host1|host2|host3)'
$testing = $::hostname ? {
    /$VARIABLE/  => 'filetest',
    default    => 'file',
  }


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5eecc840-5ab9-4636-a9be-492e8f65250c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Francisco José Bejarano

unread,
Jan 15, 2014, 8:11:09 AM1/15/14
to puppet...@googlegroups.com
Not runs

I have tried with all combinatios of quotes, arrays, hiera, etc. Only runs with literal values in the expression even I have replaced the selector with if statement

if $::hostname [ $variable ] {

and neither runs only with literal values

if $::hostname [ "host1","host2","host3" ] {

If anyone knows how it is done...

Francisco José Bejarano

unread,
Jan 15, 2014, 9:02:08 AM1/15/14
to puppet...@googlegroups.com
With this runs

hiera yaml

HOSTS_TESTING:
        - 'host1'
        - 'host2'
        - 'host3'


and manifest

$HOSTS_TESTING = hiera_array('HOSTS_TESTING')

  if $::hostname in $HOSTS_TESTING {

    $testing = 'filetest'
  } else {
      $testing = 'file'
  }

Felix Frank

unread,
Jan 15, 2014, 9:35:54 AM1/15/14
to puppet...@googlegroups.com
General remark: You should use hiera() to retrieve that value.
hiera_array() is only useful in very specific situations, and only if
you have a non-trivial hierarchy.
Reply all
Reply to author
Forward
0 new messages