1

有没有办法将所有现有的 ssh 密钥从 /root/.ssh/authorized_keys 自动导入 puppet?例子:

如果我在 /root/.ssh/ssh_authorized_keys 中有以下内容:

ssh-rsa AAAAakljsehrkjysdfjkhasdkfhskjghg== userA@hostA
ssh-rsa AAAAajklrkljeykljrsyehkrjryekjdkj== userB@hostB

我想运行类似的东西:

puppet resource ssh_authorized_key

并获得以下输出:

ssh_authorized_key {'userA':
    ensure => present,
    key    => 'AAAAakljsehrkjysdfjkhasdkfhskjghg==',
    type   => 'ssh-rsa',
    name   => 'userA@hostA',
    user   => 'root',
}
ssh_authorized_key {'userB':
    ensure => present,
    key    => 'AAAAajklrkljeykljrsyehkrjryekjdkj==',
    type   => 'ssh-rsa',
    name   => 'userB@hostB',
    user   => 'root',
}

这有可能吗?

4

1 回答 1

6

这可能有点矫枉过正,但您可以运行blueprint并获取所需的部分,或者一个简单的 bash 脚本:

while read line; do 
    keytype=$(echo $line | awk '{print $1}'); 
    keystr=$(echo $line | awk '{print $2}'); 
    username=$(echo $line | awk '{print $3}');

    echo "ssh_authorized_key {'$(echo $username | awk -F'@' '{print $1}')':"; 
    echo "  ensure => present,"; 
    echo "  key => '$keystr',"; 
    echo "  type => '$keytype',"; 
    echo "  name => '$username',"; 
    echo "  user => '$(whoami)',"; 
    echo "}"; 
done < .ssh/authorized_keys

来源:http ://shtuff.it/article/7/Generate_Puppet_ssh_authorized_keys_resource_from_existing_keys

于 2013-02-11T17:34:58.467 回答