How to get value

12 views
Skip to first unread message

Albert Shih

unread,
Jun 23, 2020, 6:15:26 AM6/23/20
to puppet...@googlegroups.com
Hi everyone,

I use a lot of accessing a variables with

class 'my_clas' (
String $var1,
String $var2,
)
{

$path = "$var1/$var2"

}

After loading my_class

class { 'my_clas':
var1 => 'something',
var2 => 'otherthing',
}

than I access to those variables

$::my_class:var1
$::my_class:path

Is it possible to do the same with define ? For example to do something
like

define my_script (
String $name,
)
{

$script_path = "/opt/local/bin/${name}",
}


then

my_script { 'first':
name => 'my_script'
}

cron { 'first':
command => $my_script::first::script_path
}

my_script { 'second':
name => 'my_script_second'
}

cron { 'second':
command => $my_script::first_second::script_path
}


Regards


--
Albert SHIH
Observatoire de Paris
xmpp: j...@obspm.fr
Heure local/Local time:
Tue 23 Jun 2020 12:08:05 PM CEST

Benjamin Ridley

unread,
Jun 23, 2020, 6:40:11 AM6/23/20
to puppet...@googlegroups.com
Defined types values exist in a 'local scope' which is only accessible to its child scopes, so there's no way to access these values using the method you're using for class variables (which are inside a named scope). 

--
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/20200623101514.GA58073%40io.chezmoi.fr.
Reply all
Reply to author
Forward
0 new messages