编程知识 cdmana.com

Ansible of Linux batch management

rsync Script writing
  • vim rsync_server.yaml # Creating scripts
- hosts:172.1.1.1
    tasks:
      - name: 01-install rsync
        yum: name=rsync state=installed
      - name:02-push conf file
        copy:src=/etc/ansible/server_file/rsync_server/rsyncd.conf dest=/etc/     # If the file is modified here , Problems when you need to restart 
      - name:03-create user
        user: name=rsync create_home=no shell=/sbin/nologin
        shell: useradd rsync -M -s /sbin/nologin
      - name:04-create backup directory
        file:path/backup state=directory owner=rsync group=rsync
      - name:05-create password directory
        copy: content=rsync_backup:demo123 dest=/etc/password mode=600
      - name: 06-start service
        service: name=rsyncd state=started enabled=yes
        
- hosts: 172.1.1.2      # If it's multiple clients , How to start 
  tasks:
    - name: 01-installed software
       yum:name=rsync state=installed
    - name: 02 -create password file
       copy:content=demo123 dest=/etc/rsync.password mode=600
    - name: 03 test data backup
        file:dest=/tmp/test.txt state=touch
    - name:04 start test
        shell:rsync -avz /tmp/test.txt rsync_backup@172.1.1.1::backup --password-file=/etc/rsync.password
        
        
        
 ansible-playbook --syntax-check rsync_server.yaml      
Common mistakes in scripts
1、 Does the grammar of the play conform to ( Space 、 The colon 、 Dash line )

2、 Whether the modules in the script are used correctly 

3、 One of the scripts name Only one task information can be written under the logo 

337

版权声明
本文为[Cat and mouse]所创,转载请带上原文链接,感谢

Scroll to Top