我是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
但它会抛出错误,如下所示
[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]#
文件已在目录中创建,文件和目录都具有权限777。
如果我尝试使用ansible复制已存在的文件,我会收到相同的错误消息。
我也尝试过非root用户,但没有成功。
提前多多感谢,
天使
答案 0 :(得分:0)
如果您有ansible> = 2.0,您可以使用remote_src,如下所示:
---
- 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 remote_src=yes
这不支持递归复制。
答案 1 :(得分:0)
你的ansible版本是什么?较新版本的ansible支持您想要的内容。如果无法升级ansible,请尝试使用 cp 命令进行简单文件复制。 cp -r 递归复制。
myObject[] array = new myObject[5];
for (int i = 0; i < array.length; i++) {
array[i] = new myObject();
}
答案 2 :(得分:0)
幸运的是,这是一个简单的修复,添加副本后您需要做的所有事情
remote_src:是