一键部署 rsync 环境
服务端:
rsyncd.conf
[ansibleTest]
path = /ansiblersync
read only = no
list = yes
uid = rsync
gid = rsync
auth users = zzl
secrets file = /etc/rsync.secrets
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
rsync.secrets
zzl:123456
1
rsync_server.yaml
- hosts: 10.0.0.21
tasks:
- name: 01-installed rsync
yum: name=rsync state=installed
#- name: 02-add port rsync 873/tcp
# firewalld: port=873/tcp zone=public static=present permanent=true
- name: 03-copy rsyncd.conf
copy: src=../ansible-file/rsync/rsyncd.conf dest=/etc/
- name: 04-copy rsync.secrets
copy: src=../ansible-file/rsync/rsync.secrets dest=/etc/ mode=600
- name: 05-create rsync group
group: name=rsync state=present
- name: 06-create rsync user
user: name=rsync state=present group=rsync shell=/sbin/nologin createhome=no
- name: 07-create public file
file: path=/ansiblersync state=directory owner=rsync group=rsync recurse=yes
- name: 08-start rsync server
shell: rsync --daemon --config=/etc/rsyncd.conf
- hosts: 10.0.0.22
tasks:
- name: 01-installed rsync
yum: name=rsync state=installed
- name: 02-create password file
copy: content=123456 dest=/etc/rsync.password mode=600
- name: 03-create rsync group
group: name=rsync state=present
- name: 04-create rsync user
user: name=rsync state=present group=rsync shell=/sbin/nologin createhome=no
- name: 05-change file mode
file: path=/temp/ owner=rsync group=rsync recurse=yes
- name: 06-check rsync
file: path=/temp/test.txt state=touch
- name: 07-start rsync client
shell: rsync -av --password-file=/etc/rsync.password /temp/ zzl@10.0.0.21::ansibleTest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
测试:ansible-playbook -C rsync_server.yaml

运行:ansible-playbook rsync_server.yaml

查看文件是否同步到了 21 主机的 /ansiblersync 下
