ansible copy modular
backup : Back up the source file before overwriting , Backup file contains time information , There are two options yes | no
content : Used in substitution "src" , You can specify the value of the file directly
dest: Will options , The absolute path of the remote host to which you want to copy the file , If the source file is a directory , Then the path must be a directory
directory_mode: Recursively set the permissions of the directory , The default is the system default permission
force: If the target host contains the file , But the content is different , If I set it to yes, Then force coverage , If no, When the file does not exist in the target location of the target host , To copy , Default yes
others: be-all file All required items in the module can be used here
src: The local address of the host file to be copied to the remote , It could be an absolute path , It could be a relative path , If the path is a directory , Copy recursively , under these circumstances , If the path uses / ending , Then copy the contents in the path , without / Copy the entire content including the directory , Be similar to rsync
ansibe copy The test case
copy File or directory
ansible -i ansiblepy.py test22 -m copy -a "src=/root/ansibletest dest=/root/"
Create a file in the directory and write the contents dest The value corresponding to the parameter must be a file , It can't be a path .
ansible -i ansiblepy.py test22 -m copy -a 'content="aaa\nbbb\n" dest=/testdir/testfile1'
take ansible In the host /testdir/copytest Copy the file to the remote host /testdir In the catalog , If it already exists in the remote host /testdir/copytest file , And the contents of the document are consistent with ansible In the host copytest The contents of the file are inconsistent , Then do not perform the copy operation , In the remote host /testdir/copytest The contents of the file will not be changed .
ansible -i ansiblepy.py test22 -m copy -a 'src=/root/testdir/ttt dest=/root/testdir/ force=no'
take ansible In the host /testdir/copytest Copy the file to the remote host /testdir In the catalog , If it already exists in the remote host /testdir/copytest file , And the contents of the document are consistent with ansible In the host /testdir/copytest The contents of the file are inconsistent , Will perform the copy operation , But before performing the copy operation , The original file in the remote host will be renamed , For backup , Then copy
ansible -i ansiblepy.py test22 -m copy -a 'src=/root/testdir/ttt dest=/root/testdir/ backup=yes'
When copying files , Specify the owner of the file , We need to pay attention to , The corresponding user must exist on the remote host .
ansible -i ansiblepy.py test11 -m copy -a 'src=/root/testdir/ttt dest=/root/ owner=root'
When copying files , Specify the permissions for the file .
ansible -i ansiblepy.py test22 -m copy -a 'src=/root/testdir/ttt dest=/root/ owner=root backup=yes mode=777'