我是 ansible 新手,我正在尝试使用 ansible 将文件从一个目录复制到远程 RH 计算机上的另一个目录。
---
- hosts: all
user: root
sudo: yes
tasks:
- name: touch
file: path=/home/user/test1.txt state=touch
- name: file
file: path=/home/user/test1.txt mode=777
- name: copy
copy: src=/home/user/test1.txt dest=/home/user/Desktop/test1.txt
Run Code Online (Sandbox Code Playgroud)
但它会抛出如下错误
[root@nwb-ansible ansible]# ansible-playbook a.yml -i hosts
SSH password:
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [auto-0000000190]
TASK: [touch] *****************************************************************
changed: [auto-0000000190]
TASK: [file] ******************************************************************
ok: [auto-0000000190]
TASK: [copy] ******************************************************************
failed: [auto-0000000190] => {"failed": true}
msg: could not find src=/home/user/test1.txt
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/root/a.retry
auto-0000000190 : ok=3 changed=1 unreachable=0 failed=1
[root@nwb-ansible ansible]#
Run Code Online (Sandbox Code Playgroud)
文件已在目录中创建,并且文件和目录的权限均为 777。
如果我尝试使用 ansible 复制现有文件,我会收到相同的错误消息。
我也以非 root 用户身份尝试过,但没有成功。
预先非常感谢,
天使