1

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

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”和“->”来确保我的资源之间的排序;但事实证明错误可能是因为我的文件的路径(它包含一个变量名)。

4

1 回答 1

6

您对该行使用单引号而不是双引号,我猜这就是变量未正确解析的原因?

IE。它应该是

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

反而

于 2013-10-31T11:36:39.397 回答