我可以在带有 ansible 的服务器和客户端服务器之间进行 ssh。两台服务器都是 Ubuntu 的 AWS 实例。此命令显示客户端服务器成功:
ansible all -m ping
这是我的剧本 site.yml 的内容:
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: Move the file foo
action: file src=/tmp/crowded/foo dest=/tmp/crowded/foo
4)当我不是 root 时,我尝试运行这个剧本:
ansible-playbook -i hosts -k -K site.yml -vvvv
但我明白了(其中 x.x.x.x 是客户端服务器的 IP 地址):
fatal: [x.x.x.x] => SSH encountered an unknown error. The output was:
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/ubuntu/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/home/ubuntu/.ansible/cp/ansible-ssh-x.x.x.x-22-root" does not exist
...
debug1: No more authentication methods to try.
Permission denied (publickey).
TASK: [Move the file foo] *****************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/ubuntu/site.retry
x.x.x.x : ok=0 changed=0 unreachable=1 failed=0
我应该怎么做才能移动 Ansible 文件?我想了解剧本是如何工作的。
最佳答案
file 模块并不是要在 Ansible 中复制文件,而是简单地确保文件存在、更改权限、创建目录和符号链接(symbolic link)等。如果您想将文件从 ansible 服务器复制到客户端计算机,那么您想要使用副本或模板模块。
我建议您仔细查看 file 的文档。 , copy , 和 template模块。请特别注意,您在示例中使用的文件模块仅识别 src
创建符号链接(symbolic link)时的参数:
path of the file to link to (applies only to state=link). Will accept absolute, relative and nonexisting paths. Relative paths are not expanded.
但是,所有这些都与您遇到的错误无关:
debug1: No more authentication methods to try. Permission denied (publickey).
您似乎对 Ansible 使用的 SSH 身份验证有疑问。您可能需要将 SSH 私钥加载到 ssh-agent 中,如 Ansible Getting Started 中所述。部分和/或确保您正在设置 private_key_file和 remote_user ansible.cfg 文件中的值正确。
关于ubuntu - Ansible 的免费版本不允许我将文件从 Ansible 服务器移动到客户端服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30092203/