第一个历程:编写剧本
服务端yaml剧本:
- hosts: 172.16.1.41
tasks:
- name: 01-install rsync
yum: name=rsync state=installed
- name: 02-push conf file
copy: src=/server/conf/rsyncd.conf dest=/etc/
- name: 03-create user rsync
user: name=rsync create_home=no shell=/sbin/nologin
- name: 04-create backup and config owner
`file: dest=/backup state=directory owner=rsync group=rsync
- name: 05-create user password file and config mode
copy: content='rsync_backup:oldboy123' dest=/etc/rsync.password mode=600 owner=root group=root
- name: 06-start rsync service
service: name=rsyncd state=started enabled=yes
客户端yaml剧本
- hosts: 172.16.1.31
tasks:
- name: 01-install rsync
yum: name=rsync state=installed
- name: 02-create password file and config mode
copy: content='oldboy123' dest=/etc/rsync.password mode=600 owner=root group=root
第二个历程:
管理机执行命令:
[root@m01 ansible-playbook 22:29:51]# ansible-playbook rsync_server.yaml
1分钟后部署完毕,在客户机上测试:
[root@nfs01 data 22:13:41]# rsync -az /etc/hosts rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
成功完成传输.