如何解决我如何使用 ansible 推送带有 SSH 密钥身份验证的剧本
我是 ansible 的新手,并尝试将剧本推送到我的节点。我想通过 ssh-keys 推送。这是我的剧本:
- name: nginx install and start services
hosts: <ip>
vars:
ansible_ssh_private_key_file: "/path/to/.ssh/id_ed25519"
become: true
tasks:
- name: install nginx
yum:
name: nginx
state: latest
- name: start service nginx
service:
name: nginx
state: started
这是我的库存:
<ip> ansible_ssh_private_key_file=/path/to/.ssh/id_ed25519
在我推送之前,我检查它是否有效:ansible-playbook -i /home/myuser/.ansible/hosts nginx.yaml --check
它给了我:
fatal: [ip]: UNREACHABLE! => {"changed": false,"msg": "Failed to connect to the host via ssh: user@ip: Permission denied (publickey,password).","unreachable": true}
在那台服务器上,我没有 root 权限,我不能执行 sudo。这就是为什么我在我的主目录中使用我自己的库存。对于要推送该 nginx 剧本的目标节点,我可以建立 SSH 连接并执行登录。公钥在远程服务器上的 /home/user/.ssh/id_ed25119.pub
我错过了什么?
解决方法
将 /etc/ansible/ansible.cfg 复制到您运行 nginx.yaml
playbook 的目录中,或按照文档的其他位置:https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-configuration-settings-locations
然后编辑该文件以更改这一行:
#private_key_file = /path/to/file
阅读:
private_key_file = /path/to/.ssh/id_ed25519
还要检查远程 user_user
条目。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。