ubuntu - Ansible 的免费版本不允许我将文件从 Ansible 服务器移动到客户端服务器

标签 ubuntu ssh ansible

我可以在带有 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_fileremote_user ansible.cfg 文件中的值正确。

关于ubuntu - Ansible 的免费版本不允许我将文件从 Ansible 服务器移动到客户端服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30092203/

相关文章:

linux - 如何通过用户通过 ssh 发送的公钥获取用户信息?

ubuntu - jenkins 使用 sudo 时出现身份验证错误

Bash:使用 SSH 在远程获取 sudo 命令的输出

linux - 模块无法启动 Ansible

android-studio - 使用 WSL Ubuntu 在 Windows 机器上配置 CAPACITOR_ANDROID_STUDIO_PATH 环境变量

java - openjdk:如何将网站添加到异常(exception)列表

git - 如何使用git将两个目录 merge 到同一个分支中

grep - 当 grep 结果为空时,Ansible shell 模块返回错误

ansible - 如何只运行 Ansible 剧本的一个角色?

python - 相同的代码,不同的错误 : Python init()