Ansible 使用命令语法复制文件
任务如下: 让我们在创建任务之前创建一个文件touch afile.txt 创建playbook test.yml以 将afile.txt作为afile_copy.txt从控制计算机复制到位于/home/ubuntu/location的主机,然后 调试上述任务以显示返回值 执行playbook(test.yml)并观察输出 我没有跟随Ansible 使用命令语法复制文件,ansible,Ansible,任务如下: 让我们在创建任务之前创建一个文件touch afile.txt 创建playbook test.yml以 将afile.txt作为afile_copy.txt从控制计算机复制到位于/home/ubuntu/location的主机,然后 调试上述任务以显示返回值 执行playbook(test.yml)并观察输出 我没有跟随 使用触摸创建了afile_copy.txt 创建了剧本,如下所示: 当我使用命令运行playbook时 ansible playbook-i myhosts t
当我使用命令运行playbook时 ansible playbook-i myhosts test.yml 它失败并显示错误消息 stderr:cp:无法统计“afile.txt”:没有这样的文件或目录
afile.txt位于/home/scrapbook/tutorial目录下。您应该使用复制模块而不是命令模块。命令模块在远程节点上执行。1)首先执行临时复制命令: ansible all-i myhosts-m copy-a“src=afile.txt dest=/home/ubuntu/” 2) 执行上述命令后,执行此PlaybBook:
- 主持人:全部
任务:- stat:path=/home/ubuntu/afile\u copy.txt 注册编号:st
- 名称:重命名 命令:mv afile.txt/home/ubuntu/afile\u copy.txt 何时:不存在圣统计 寄存器:输出
- 调试:var=output
- name: copy files
hosts: all
tasks:
- name: copy file
copy: src=afile.txt dest=/home/ubuntu/afile_copy.txt
register:output
- debug: var=output
使用hypen“-”而不是dot。使用hypen“-”而不是dot(-hosts:all,-stat:…,-name:…,-debug:…)您应该包含一些关于更改的注释,您添加了一个标题并以不同的方式定义了命令,因此您应该解释为什么这样做,而这段代码可能提供了问题的解决方案,最好添加上下文来说明它为什么/如何工作。这可以帮助未来的用户学习,并将这些知识应用到他们自己的代码中。在解释代码时,用户可能会以投票的形式向您提供正面反馈。
- name: copy files
hosts: all
tasks:
- name: copy file
copy: src=afile.txt dest=/home/ubuntu/afile_copy.txt
register:output
- debug: var=output
---
- name: copy files
hosts: all
tasks:
- name: copy file
copy:
src: afile.txt
dest: /home/ubuntu/afile_copy.txt
register: output
- debug: var=output