Ask Your Question
0

Substitute parameter in fact name

asked 2014-03-31 03:28:31 -0500

selivan gravatar image

Here is custom fact:

require 'etc'

Etc.passwd do |user|
    Facter.add("homedir_#{user.name}".intern) do
        setcode { user.dir }
    end
end

It' taken here: https://ask.puppetlabs.com/question/5373/how-to-reference-a-users-home-directory/ It determines users home dir locations.

Here is defined type:

define ssh_keys::key ($user) {

$home = $::homedir_#{user}
#$home = $::homedir_root

if $home != undef {

file { "$home/.ssh/":
    ensure => directory,
}

file { "$home/.ssh/authorized_keys":
    ensure => file,
    source => "puppet:///modules/ssh_keys/$user",
    }
}

}

It does not work for $::homedir_#{user}, but works for explicitly defined fact $::homedir_root. What is wrong here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-03-31 07:17:26 -0500

selivan gravatar image

Here is solution:

$mule = "ipaddress_${name}"
$donkey = inline_template("<%= scope.lookupvar(mule) %>")
edit flag offensive delete link more

Comments

Yes, but keep in mind that an inline_template is computationally expensive. I've found that the most direct way of tackling this particular issue is to manage the user and ...(more)

ffrank gravatar imageffrank ( 2014-04-03 08:01:57 -0500 )edit

Task is to add user's key, only if user exists

selivan gravatar imageselivan ( 2014-04-03 08:39:37 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-03-31 03:28:31 -0500

Seen: 59 times

Last updated: Mar 31 '14