Ssh ansible playbook公钥问题
我有一个基本的剧本,它将位于public_keys文件夹中的所有公钥附加到.ssh/authorized_keys中的用户文件夹中:Ssh ansible playbook公钥问题,ssh,key,ansible,ansible-playbook,Ssh,Key,Ansible,Ansible Playbook,我有一个基本的剧本,它将位于public_keys文件夹中的所有公钥附加到.ssh/authorized_keys中的用户文件夹中: - hosts: default vars: user: user1 tasks: - name: Set up authorized_keys for the user authorized_key: user={{ user }} key="{{ item }}" with_fileglob: - public_keys/*.pub 当我
- hosts: default
vars:
user: user1
tasks:
- name: Set up authorized_keys for the user
authorized_key: user={{ user }} key="{{ item }}"
with_fileglob:
- public_keys/*.pub
当我在ansible上运行它时,它会给我这个错误,我几乎被它卡住了:
TASK [Set up authorized_keys for the user] ************************
failed: [default] => (item=/Users/trax/Git/ansible-keys/public_keys/test.pub) => {"failed": true, "item": "/Users/trax/Git/ansible-keys/public_keys/test.pub", "msg": "invalid key specified: /Users/trax/Git/ansible-keys/public_keys/test.pub"}
公钥文件是完全有效的,因为我目前正在使用它,它工作得非常好。它没有任何注释,我会将它粘贴到这里,以便您可以看到:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4e+RLnQAqo3azuFzbynD9n6L7Qc2NjEwNLQRqKOd17532rHAhGOxz9ZV7ca5J6y9Z8QyV2EP9oXXpXd7I9oG1ybiU2cOmMQ7mIMFnMgy90dgVmF4X4Rj3fPch271TIQhvBH36L1eagk98Tlj32zepHNmC7ECFiAUihxXsuGAcFK4l9Y3s0HZe913E1ewUxXjUZAaqmzEQwW621hWDDTU1zUCnPPqEe6DFy6PUP8YL8mLbbKuSL2W6bD7rzm1axZANvoYeD5egvzwSMeZ8f+XF3MbuyhiJhGEFjwDfDkibP4bwQqZm5IdI1c0Ot2X67OHFsHx04gbs6ZzBkD39Z6Jr trax@M.local
有什么建议吗?非常感谢…键参数的参数必须是键,而不是文件的路径,而是实际内容或url。从文件中:
将SSH公钥设置为字符串或自1.9 url起
因此,您可以添加一个任务,将密钥读取到注册变量中,然后循环该任务以安装密钥:
- hosts: all
tasks:
- name: read keys
# This needs to run on localhost, because that's where
# the keys are stored.
delegate_to: localhost
command: cat {{item}}
# Register the results of this task in a variable called
# "keys"
register: keys
with_fileglob:
- "public-keys/*.pub"
- name: show what was stored in the keys variable
debug:
var: keys
- authorized_key:
user: fedora
key: "{{item.stdout}}"
with_items: "{{keys.results}}"
见
有关详细信息。键参数的参数必须是键,而不是文件的路径,而是实际内容或url。从文件中:
将SSH公钥设置为字符串或自1.9 url起
因此,您可以添加一个任务,将密钥读取到注册变量中,然后循环该任务以安装密钥:
- hosts: all
tasks:
- name: read keys
# This needs to run on localhost, because that's where
# the keys are stored.
delegate_to: localhost
command: cat {{item}}
# Register the results of this task in a variable called
# "keys"
register: keys
with_fileglob:
- "public-keys/*.pub"
- name: show what was stored in the keys variable
debug:
var: keys
- authorized_key:
user: fedora
key: "{{item.stdout}}"
with_items: "{{keys.results}}"
见
有关详细信息,请参见。假设密钥文件是控制机器的本地文件,则可以很容易地使用a获取密钥内容,例如:
- hosts: default
tasks:
- authorized_key:
user: '{{ user }}'
key: '{{ lookup('file', item) }}'
with_fileglob: public_keys/*.pub
假设密钥文件是控制机器的本地文件,则使用a获取密钥内容很容易,例如:
- hosts: default
tasks:
- authorized_key:
user: '{{ user }}'
key: '{{ lookup('file', item) }}'
with_fileglob: public_keys/*.pub
由于大多数都是旧版本,我有一个适合我的更新版本 -名称:设置从文件中获取的授权密钥 授权密钥: 用户:yourtargetusername 国家:现在 键:{{lookup'file','yourtargetkey.pub'}
由于大多数都是旧版本,我有一个适合我的更新版本 -名称:设置从文件中获取的授权密钥 授权密钥: 用户:yourtargetusername 国家:现在 键:{{lookup'file','yourtargetkey.pub'}