Ansible能否只部署一次询问密码的SSH公钥?
我想知道如何使用Ansible将我的SSH公钥复制到许多主机 第一次尝试:Ansible能否只部署一次询问密码的SSH公钥?,ansible,ssh-keys,ansible-2.x,Ansible,Ssh Keys,Ansible 2.x,我想知道如何使用Ansible将我的SSH公钥复制到许多主机 第一次尝试: ansible all -i inventory -m local_action -a "ssh-copy-id {{ inventory_hostname }}" --ask-pass 但是我有一个错误在配置的模块路径中找不到模块本地\u操作 第二次尝试使用剧本: - hosts: all become: no tasks: - local_action: command ssh-copy-id {{ i
ansible all -i inventory -m local_action -a "ssh-copy-id {{ inventory_hostname }}" --ask-pass
但是我有一个错误在配置的模块路径中找不到模块本地\u操作
第二次尝试使用剧本:
- hosts: all
become: no
tasks:
- local_action: command ssh-copy-id {{ inventory_hostname }}
最后,我输入了每个托管主机的密码:
ansible all -i inventory --list-hosts | while read h ; do ssh-copy-id "$h" ; done
如何在将公共SSH密钥部署到多台主机时只填写一次密码?
编辑:我已成功地使用以下来自的剧本将SSH公钥复制到多个远程主机 根据,字段
user
应为必填字段,但在没有此字段的情况下似乎可以使用。因此,当与此命令行一起使用时,上述通用剧本可用于任何用户:
ansible-playbook -i inventory authorized_key.yml -u "$USER" -k
为什么不使用模块
并使用
-u remote\u user\u name-k运行playbook
对于我来说,user
变量是必需的。我已将其设置为“{{ansible\u user\u id}}”
以使用当前用户名,但如果需要,可以将其设置为其他名称。失败!=>{“已更改”:false,“msg”:“缺少必需参数:用户”}密码?假设这是Ansible主机第一次连接到新的远程主机。否则为什么不复制ssh id呢
ansible-playbook -i inventory authorized_key.yml -u "$USER" -k
- hosts: all
tasks:
- authorized_key:
user: remote_user_name
state: present
key: "{{ lookup('file', '/local/path/.ssh/id_rsa.pub') }}"