[Ansible]copy 模块

官网

[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

posted @ 2020-09-14 14:58  LeoShi2020  阅读(271)  评论(0编辑  收藏  举报