ansible 远程拷贝
时间: 2023-09-21 15:10:52 浏览: 50
您好!对于远程拷贝,Ansible 提供了 `copy` 模块和 `synchronize` 模块来实现文件传输。
使用 `copy` 模块可以将本地文件复制到远程主机上,示例代码如下:
```yaml
- name: Copy file to remote host
copy:
src: /path/to/local/file
dest: /path/to/remote/file
remote_src: yes # 设置为 yes 以使用本地文件路径
```
使用 `synchronize` 模块可以在本地和远程主机之间同步文件夹,示例代码如下:
```yaml
- name: Synchronize folder to remote host
synchronize:
src: /path/to/local/folder/
dest: /path/to/remote/folder/
```
这些模块都可以与 Ansible playbook 结合使用,您可以根据需要选择适合的方式进行远程拷贝操作。
相关问题
ansible 批量拷贝命令
可以使用ansible的copy模块来批量拷贝文件,命令如下:
ansible <host_group> -m copy -a "src=<source_file> dest=<destination_directory>"
其中,<host_group>是主机组名,<source_file>是源文件路径,<destination_directory>是目标目录路径。
ansible远程删除文件
以下是使用Ansible远程删除文件的方法:
```shell
ansible all -m file -a "dest=/etc/hosts state=absent"
```
上述命令中,`-m file`表示使用file模块,`-a "dest=/etc/hosts state=absent"`表示删除`/etc/hosts`文件。执行该命令后,Ansible会在所有主机上删除`/etc/hosts`文件。