将主控端的文件复制到远程主机,只针对文件
src 源文件路径
dest 目标文件路径
content 将指定内容覆盖写入到目标主机文件中
force=no 当主控端拷贝的文件名和目标名一致,但是内容不一致,放弃拷贝
force=yes 当主控端拷贝的文件名和目标名一致,但是内容不一致,则进行覆盖
backup=yes 当主控端拷贝的文件名和目标名一致,但是内容不一致,则进行备份https://www.cndba.cn/hbhe0316/article/18796
https://www.cndba.cn/hbhe0316/article/18796
1.将源文件,copy到被控端https://www.cndba.cn/hbhe0316/article/18796
https://www.cndba.cn/hbhe0316/article/18796
[root@ansible ~]# ansible mysql -m copy -a 'src=/root/test.sh dest=/tmp/test.sh'
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"checksum": "fef3362b2569d5051aacfc796f94b9361ed17501",
"dest": "/tmp/test.sh",
"gid": 0,
"group": "root",
"md5sum": "fffb69482b3210a71d551f6a55229669",
"mode": "0644",
"owner": "root",
"size": 26,
"src": "/root/.ansible/tmp/ansible-tmp-1636858197.78-2717-153122870288434/source",
"state": "file",
"uid": 0
}
2.将指定内容覆盖到被控端文件内https://www.cndba.cn/hbhe0316/article/18796https://www.cndba.cn/hbhe0316/article/18796
[root@ansible ~]# ansible mysql -m copy -a "content='This is just a test' dest=/tmp/test.sh"
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"checksum": "7265cdc53d4a78743e5b09d9a842e85d54fe5b44",
"dest": "/tmp/test.sh",
"gid": 0,
"group": "root",
"md5sum": "df0a9498a65ca6e20dc58022267f339a",
"mode": "0644",
"owner": "root",
"size": 19,
"src": "/root/.ansible/tmp/ansible-tmp-1636858416.25-2753-247910343979913/source",
"state": "file",
"uid": 0
}
3.将文件发送到被控端,如果内容不同则进行备份,并覆盖https://www.cndba.cn/hbhe0316/article/18796
[root@ansible ~]# ansible mysql -m copy -a "src=/root/test.sh dest=/tmp/test.sh backup=yes"
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"backup_file": "/tmp/test.sh.4331.2021-11-14@11:05:53~",
"changed": true,
"checksum": "fef3362b2569d5051aacfc796f94b9361ed17501",
"dest": "/tmp/test.sh",
"gid": 0,
"group": "root",
"md5sum": "fffb69482b3210a71d551f6a55229669",
"mode": "0644",
"owner": "root",
"size": 26,
"src": "/root/.ansible/tmp/ansible-tmp-1636859151.74-2813-22864520776498/source",
"state": "file",
"uid": 0
}
[root@ansible ~]# ansible mysql -m shell -a "ls /tmp/test*"
192.168.56.88 | CHANGED | rc=0 >>
/tmp/test.sh
/tmp/test.sh.4331.2021-11-14@11:05:53~
4.拷贝过程中修改属主
权限参数
owner 属主
group 属组
mode 权限https://www.cndba.cn/hbhe0316/article/18796
https://www.cndba.cn/hbhe0316/article/18796
https://www.cndba.cn/hbhe0316/article/18796
[root@ansible ~]# ansible mysql -m copy -a "src=/root/test.sh dest=/tmp/test.sh owner=mysql group=mysql mode=666"
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"checksum": "fef3362b2569d5051aacfc796f94b9361ed17501",
"dest": "/tmp/test.sh",
"gid": 1000,
"group": "mysql",
"mode": "0666",
"owner": "mysql",
"path": "/tmp/test.sh",
"size": 26,
"state": "file",
"uid": 1000
}
应该看到copy过去的文件属主也已经改了。
[root@ansible ~]# ansible mysql -m shell -a "ls -l /tmp/test*"
192.168.56.88 | CHANGED | rc=0 >>
-rw-rw-rw- 1 mysql mysql 26 Nov 14 11:05 /tmp/test.sh
-rw-r--r-- 1 root root 19 Nov 14 10:53 /tmp/test.sh.4331.2021-11-14@11:05:53~
版权声明:本文为博主原创文章,未经博主允许不得转载。
ansible
相关文章
暂无评论...