i have a small Problem i wrote some code that works fine now i want to add the erb for it and reference variable defined in the yaml. But im unable to access the variables referenced in that yaml.
Dou you have any tips ?
Some examples
in my init.pp i call this resource
if $rrp_config {
create_resources(rrp_config, $rrp_config)
}
im my erb i would look to access the variable ip now how can i get there ?
And as plus how can i ensure that the ip only gets set on the host that matches its hostname with the variable rrp_host ?
I’d also add types to the resource to ensure they’re correct. For example, String can be used to enforced some value. The catalog will fail to compile giving you more correct output where it went wrong.
Instead of $::hostname the more modern way is $facts['hostname'].
i should add that we are still (shame on us) on puppet 3.8 due to the satellite 6 and are now migration to puppet 5(but we still need this running on puppet 3.8) . The “full” init looks like
init.pp
class pcs (
$pcssudoer = '',
$pcssudoextrarules = '',
$requiretty = true,
$rrp_config = undef,
) {
tag 'pcs'
...
if $rrp_config {
create_resources(rrp_config, $rrp_config)
}
and the full content of the rrp_config.pp is
# This a Resource over which init.pp loops
define pcs::rrp_config (
$rrp_name = $title,
$ip = undef,
$rrp_host = undef,
$rrp_interface = undef,
) {
host { "${rrp_name}_name":
ensure => present,
name => $rrp_name,
ip => $ip
}
if $rrp_host == $::hostname {
file { "/etc/sysconfig/network-scripts/ifcfg-${rrp_interface}-${rrp_host}":
ensure => 'file',
path => "/etc/sysconfig/network-scripts/ifcfg-${rrp_interface}",
owner => 'root',
group => 'root',
mode => '0644',
content => template('pcs/ifcfg.erb'),
}
} else {
notify {"rrp_name = ${rrp_name} and hostname = ${::hostname} and inteface = ${rrp_interface}":}
}
}