详解ansible批量管理服务(6)

第二个历程: 编写剧本信息

[root@m01 ansible_playbook]#vim rsync_auto.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
   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

恢复环境剧本

[root@m01 ansible_playbook]#vim rsync_backup.yaml 
- hosts: rsync_server
 tasks:
  - name: 01:delete conf file
   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
   service: name=rsyncd state=stopped enabled=no

- hosts: rsync_client
 tasks:
  - name: 01:delete password file
   file: path=/etc/rsync.password state=absent

1.9 ansible剧本实现nfs一键化部署

第一个历程: 按照模块方式,完成服务每个步骤部署

服务端配置

01. 安装部署软件程序: rpcbind nfs-utile

ansible nfs_server -m yum -a "name=rpcbind state=installed"
ansible nfs_server -m yum -a "name=nfs-utile state=installed"

02. 编写配置文件:配置文件要提前写好

# 批量管理主机写好的配置文件推送给服务端/etc/ansible-playbook/nfs.conf 
ansible nfs_server -m copy -a "src=/etc/ansible/ansible_playbook/nfs.conf dest=/etc/exports"

03. 创建共享目录:

ansible nfs_server -m file -a "path=/data/ state=directory owner=nfsnobody group=nfsnobody"

04. 启动程序服务:

ansible nfs_server -m service -a "name=rpcbind state=started enabled=yes"
ansible nfs_server -m service -a "name=nfs state=started enabled=yes"

客户端配置:

01. 安装部署软件

ansible nfs_client -m yum -a "name=nfs-utile state=installed"

02. 挂载共享目录

ansible nfs_client -m mount -a "src=172.16.1.31:/data/ path=/mnt fstype=nfs state=mounted"

第二个历程编写剧本: