Linux批量管理之ansible

rsync剧本编写
  • vim rsync_server.yaml #创建剧本
- 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/     #此处如果是修改了文件,需要重启的时候出现的问题
      - 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      #如果是多台客户端,怎么启动
  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 [email protected]::backup --password-file=/etc/rsync.password
        
        
        
 ansible-playbook --syntax-check rsync_server.yaml      
剧本常见错误
1、剧本语法规范是否符合(空格、冒号、短横线)

2、剧本中的模块使用是否正确

3、剧本中的一个name标识下面只可以写一个任务信息

337

你可能感兴趣的:(linux)