#参数
decrypt
yes / no
默认为yes
此选项控制使用vault的源文件的自动解密。
src
要将文件复制到远程服务器的本地路径; 可以是绝对的或相对的。
如果path是一个目录,它将被复制(包括源文件夹名称)递归到dest。
如果path是一个目录并以“/”结尾,则只有该目录的内部内容被复制到目标。 否则,如果它不以“/”结尾,则复制具有所有内容的目录本身。
如果path是一个文件并且dest以“\”结尾,则该文件将被复制到具有相同文件名的文件夹中
dest
文件应该复制到的远程绝对路径。 如果src是一个目录,它也必须是一个目录。
在“双引号”中使用\作为路径分隔符或\\。
如果dest以\ source结尾,或者source的内容将被复制到目录而不重命名。
如果dest是不存在的路径,那么只有当dest以“/”或“\”结尾,或者src是一个目录时才会创建它。
如果src和dest是文件,并且dest的父目录不存在,则该任务将失败。
force
yes / no
默认为yes
如果设置为yes,则只有在内容与目标不同时才会传输文件。
如果设置为no,则仅在目标不存在时传输文件。
如果设置为no,则不执行内容的校验,这可以帮助提高较大文件的性能。
remote_src
yes / no
默认为no
如果为no,它将在原始/主机上搜索src,如果为yes,它将转到src的远程/目标拿取文件
eg:1.
拷贝文件到目标主机
dest=d:/temp 目标目录如果没有/ 则会重命名文件为temp
dest=d:/temp/ 目标目录temp后面就/ 则会拷贝到temp目录下(目录不存在会创建)
ansible -i hosts win_1.98 -m win_copy -a 'src=/etc/passwd dest=d:/temp'
ansible -i hosts win_1.98 -m win_copy -a 'src=/etc/passwd dest=d:/temp/'
eg2:
将目录拷贝到目标主机
src=/windows 如果src后的目录没有/结尾 则会把整个目录拷贝到目标主机
src=/windows/ 如果src后的目录带有/ 则会吧目录下的所有文件都拷贝到目标主机
ansible -i hosts win_1.98 -m win_copy -a 'src=/etc/ansible/playbook/windows dest=d:/temp/'
ansible -i hosts win_1.98 -m win_copy -a 'src=/etc/ansible/playbook/windows/ dest=d:/temp/'
eg3:
在远程主机上拷贝文件
playbook:
#拷贝单个文件,不修改文件名
- name: Copy a single file keeping the filename
win_copy:
src: /src/myfiles/foo.conf
dest: c:\temp\
#拷贝单个文件,并重命名
- name: Copy a single file
win_copy:
src: /srv/myfiles/foo.conf
dest: c:\Temp\renamed-foo.conf
#拷贝目录
- name: Copy folder to c:\temp (results in C:\Temp\temp_files)
win_copy:
src: files/temp_files
dest: c:\Temp
#拷贝目录下的所有文件
- name: Copy folder contents recursively
win_copy:
src: files/temp_files/
dest: c:\Temp
#在远程主机上拷贝文件
- name: Copy a single file where the source is on the remote host
win_copy:
src: C:\temp\foo.txt
dest: C:\ansible\foo.txt
remote_src: True
#在远程主机上拷贝目录
- name: Copy a folder recursively where the source is on the remote host
win_copy:
src: C:\temp
dest: C:\ansible
remote_src: True
#修改文件内容
- name: Set the contents of a file
win_copy:
dest: C:\temp\foo.txt
content: abc123