将文件的内容存储在变量中

时间:2013-10-30 22:16:48

标签: file puppet

我正在尝试提取文件的内容并将其存储在变量中。我的代码看起来像这样。

define ssh_user (
        $name = undef,
        $role = undef,
        $password = undef,
        $usergroup = undef, ) {

                user { $name:
                        home => "/home/${name}/",
                        ensure => present,

                }->

                exec { "generate keys ${name}":
                        user => $name,
                        command => '/bin/echo -e "\n\n\n" | ssh-keygen -t rsa',
                        path => "/usr/bin/",
                }->
               file { "/home/${name}/.ssh/auhorized_keys":
                        ensure => file,
                        mode => 700,
                        source => "/home/${name}/.ssh/id_rsa.pub",
               } 
                @@node_user { $name:
                        require => File["/home/${name}/.ssh/auhorized_keys"],
                        key => file('/home/${name}/.ssh/id_rsa.pub'),    ## line causing error
                        role => "ssh::users::${name}::role",
                }
}

我收到以下错误,

Error: Could not find any files from /home/${name}/.ssh/id_rsa.pub at /etc/puppet/manifests/sshd_setup.pp:90 on node puppet.colo.seagate.com
Error: Could not find any files from /home/${name}/.ssh/id_rsa.pub at /etc/puppet/manifests/sshd_setup.pp:90 on node puppet.colo.seagate.com

我正在为一组用户创建文件,并将文件的内容存储在一个可变的中。 将文件内容存储在变量中后,我使用它来创建导出的资源。

我尝试使用“require”和“ - >”确保我的资源之间的顺序;但事实证明错误可能是因为我的文件的路径(它包含一个变量名)。

1 个答案:

答案 0 :(得分:6)

你使用单引号而不是双行引号,我猜这就是为什么变量没有被正确解析?

即。它应该是

key => file("/home/${name}/.ssh/id_rsa.pub"),    ## line causing error

代替