Centos7.6rsync利用剧本部署,清空环境

剧本价值及作用


  1. 可以将多个批量操作模块功能整合
  2. 简化运维工作复杂度

操作前准备


1.备份服务器 IP:172.16.1.41
2.nfs服务器 IP:172.16.1.31
3.web服务器 IP:172.16.1.7

1.修改主机文件

#rsync服务
[rsync:children]
rsync_server
rsync_client
[rsync_server]
172.16.1.41
[rsync_client]
172.16.1.31
172.16.1.7

2.创建存放剧本的目录

mkdir /etc/ansible/ansible_playbook  --- 创建剧本汇总目录

3.创建rsync安装剧本文件(rsync_xxx.yaml)

服务端配置信息:
- hosts: rsync_server
      tasks:
        - name: 01:install rsync  ---安装软件程序
          yum: name=rsync state=installed
        - name: 02:copy conf file   ---将配置文件发送到被管理端
          copy: src=/etc/ansible/conf_file/rsyncd.conf dest=/etc/
        - name: 03:create rsync user   ---创建虚拟用户
          user: name=rsync create_home=no shell=/sbin/nologin
        - name: 04:create password file   ---创建密码文件更改权限并加入密码
          copy: content='rsync_backup:oldboy123' dest=/etc/rsync.password mode=600
        - name: 05:create backup dir   ---创建共享目录更改文件属组属主
          file: path=/backup state=directory owner=rsync group=rsync
        - name: 06:boot rsync server   ---启动rsync服务
          service: name=rsyncd state=started enabled=yes
客户端配置信息:    
    - hosts: rsync_client
      tasks:
        - name: 01:create password file   ---创建密码文件修改文件权限
          copy: content='oldboy123' dest=/etc/rsync.password mode=600

4.创建rsync卸载剧本文件(rsync_xxx.yaml)

 - hosts: rsync_server
      tasks:
        - name: 01:delete conf file   ---卸载rsync服务
          file: path=/etc/rsyncd.conf state=absent
        - name: 02:delete rsync user   ---删除虚拟用户
          user: name=rsync state=absent 
        - name: 03:delete password file   ---删除密码文件
          file: path=/etc/rsync.password state=absent
        - name: 04:delete backup dir   ---删除共享目录
          file: path=/backup/ state=absent
        - name: 05:boot rsync server   ---关闭rsync服务
          service: name=rsyncd state=stopped enabled=no
 
    - hosts: rsync_client
      tasks:
        - name: 01:delete password file   ---删除密码文件
          file: path=/etc/rsync.password state=absent

以上就是所有内容

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。