NFS服务剧本

第一个历程: 创建几个目录
   [root@m01 ansible-playbook]# tree nfs-file/
   nfs-file/
   ├── nfs-client
   └── nfs-server
   
   第二个历程: 编写剧本信息
   主机清单:

vim /etc/ansible/hosts
   [nfs:children]
   nfs_server
   nfs_client
   [nfs_server]
   172.16.1.31
   [nfs_client]
   172.16.1.7
   172.16.1.8
   172.16.1.9

vim nfs-server.yaml

- hosts: nfs
  tasks:
    - name: 01-install nfs software
      yum:
        name: ['nfs-utils','rpcbind']
        state: installed

- hosts: nfs_server
  vars:
    Data_dir: /data
  tasks:
    - name: 01-copy conf file
      copy: src=/etc/ansible/ansible-playbook/nfs-file/nfs-server/exports dest=/etc
      notify: restart nfs server
    - name: 02-create data dir
      file: path={{ Data_dir }} state=directory owner=nfsnobody group=nfsnobody 
       # path: ['data01','data02','data03'] 
       # state: directory 
       # owner: nfsnobody 
       # group: nfsnobody
    - name: 03-boot server
      #service: name=rpcbind state=started enabled=yes
      #service: name=nfs state=started enabled=yes
      service: name={{ item }} state=started enabled=yes
      with_items:
        - rpcbind
        - nfs     
 
  handlers:
    - name: restart nfs server
      service: name=nfs state=restarted
       
- hosts: nfs_client
  vars:
    Data_dir: /data
  tasks:
    - name: 01-mount
      mount: src=172.16.1.31:{{ Data_dir }} path=/mnt fstype=nfs state=mounted
    - name: 02-check mount info
      shell: df -h|grep /data
      register: mount_info
    - name: display mount info
      debug: msg={{ mount_info.stdout_lines }}   

   
   

第三个历程: 进行剧本测试

 ansible-playbook --syntax-check  nfs_server.yaml

 ansible-playbook -C  nfs_server.yaml

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(批量管理工具)