ansibile剧本---实现一键部署rsync备份服务

[root@m01 ansible-playbook]# vim rsync-判断功能.yaml
- name: 02-push conf file
copy: src=/etc/ansible/server_file/rsync_server/rsyncd.conf dest=/etc/
- name: 03-create user
user: name=rsync create_home=no shell=/sbin/nologin
- name: 04-create dir
file: path=/backup state=directory owner=rsync group=rsync
- name: 05-create password file
copy: content=rsync_backup:oldboy123 dest=/etc/rsync.password mode=600
- name: 06-start rsync server
service: name=rsyncd state=started enabled=yes

 

- hosts: 172.16.1.31,172.16.1.7
tasks:
- name: 01-install rsync
yum: name=rsync state=installed
- name: 02-cerate password file
copy: content=oldboy123 dest=/etc/rsync.password mode=600
- name: 03-create test file
file: dest=/tmp/test_nfs.txt state=touch
when: (ansible_hostname == "nfs01")
- name: 04-create test file
file: dest=/tmp/test_web.txt state=touch
when: (ansible_hostname == "web01")
- name: 05-chech test_nfs data
shell: rsync -avz /tmp/test_nfs.txt rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
when: (ansible_hostname == "nfs01")
- name: 06-check test_web data
shell: rsync -avz /tmp/test_web.txt rsync_backup@172.16.1.41::web --password-file=/etc/rsync.password
when: (ansible_hostname == "web01")

posted @ 2020-07-19 15:55  陈帅帅_大侠  阅读(158)  评论(0编辑  收藏  举报