码迷,mamicode.com
首页 > 其他好文 > 详细

[Ansible]copy 模块

时间:2020-09-18 01:09:51      阅读:28      评论:0      收藏:0      [点我收藏+]

标签:copy   debug   debuginfo   meta   lin   文件备份   lang   change   root   

官网

[root@ceph1 ~]# cat a.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch&infra=$infra&content=$contentdir
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch&infra=$infra&content=$contentdir
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch&infra=$infra&content=$contentdir
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

# 将a.repo传送到其他服务器
[root@ceph1 ~]# ansible webservers -m copy -a "src=./a.repo dest=/tmp/a.repo"

# 修改配置文件
[root@ceph1 ~]# echo ‘add‘ >> a.repo

# 再次发送带备份参数
[root@ceph1 ~]# ansible all -m copy -a "src=./a.repo dest=/tmp/a.repo backup=yes"

# 查看配置文件备份
[root@ceph1 ~]# ansible all -m shell -a "ls -l /tmp/*.repo*"
ceph3 | CHANGED | rc=0 >>
-rw-r--r-- 1 root root 1054 9月  14 12:00 /tmp/a.repo
-rw-r--r-- 1 root root 1050 9月  14 12:00 /tmp/a.repo.23055.2020-09-14@12:00:57~
ceph2 | CHANGED | rc=0 >>
-rw-r--r-- 1 root root 1054 9月  14 12:00 /tmp/a.repo

# 修改文件用户权限
[root@ceph1 ~]# ansible all -m copy -a "src=./a.repo dest=/tmp/a.repo owner=nobody group=nobody"
[root@ceph1 ~]# ansible all -m shell -a "ls -l /tmp/*.repo*"
ceph3 | CHANGED | rc=0 >>
-rw-r--r-- 1 nobody nobody 1054 9月  14 12:00 /tmp/a.repo
-rw-r--r-- 1 root   root   1050 9月  14 12:00 /tmp/a.repo.23055.2020-09-14@12:00:57~
ceph2 | CHANGED | rc=0 >>
-rw-r--r-- 1 nobody nobody 1054 9月  14 12:00 /tmp/a.repo

# 修改目的文件权限
[root@ceph1 ~]# ansible all -m copy -a "src=./a.repo dest=/tmp/a.repo mode=0777"
[root@ceph1 ~]# ansible all -m shell -a "ls -l /tmp/*.repo*"
ceph3 | CHANGED | rc=0 >>
-rwxrwxrwx 1 nobody nobody 1054 9月  14 12:00 /tmp/a.repo
-rw-r--r-- 1 root   root   1050 9月  14 12:00 /tmp/a.repo.23055.2020-09-14@12:00:57~
ceph2 | CHANGED | rc=0 >>
-rwxrwxrwx 1 nobody nobody 1054 9月  14 12:00 /tmp/a.repo

END

[Ansible]copy 模块

标签:copy   debug   debuginfo   meta   lin   文件备份   lang   change   root   

原文地址:https://www.cnblogs.com/leoshi/p/13666727.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!