编写剧本规范:
http://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html

遵循pyyaml
①. - 用法说明,表示列表显示的内容
    水果信息:
      - 苹果
      - 香蕉
      - 西瓜
②. : 用法说明:
    姓名: 张三
    性别: 男
    人员信息:
    - 运维人员: sa
    - 开发人员: dev
    - 存储人员: dba
③. 空格 用法说明:
    对内容进行分级时,需要有两个空格表示分级
    软件安装步骤:
      - 服务端安装步骤:
        第一个里程碑: 检查软件是否安装
        第二个里程碑: 编写配置文件内容
      - 客户端安装步骤:
    补充:必须使用空格分隔ansible剧本级别,一定不要使用tab键进行分割

rsync一键部署剧本:(用的是-标识,只是格式问题,显示成了。)
vim /etc/ansible/ansible-playbook/test.yaml

  • hosts: 172.16.1.41
    tasks:

    • name: step01:install rsync
      yum: name=rsync state=installed
    • name: step02:edit rsync conf file
      copy: src=/etc/ansible/conf/rsync_conf/rsyncd.conf dest=/etc/
    • name: step03:create rsync user
      user: name=rsync state=present createhome=no shell=/sbin/nologin
    • name: step04:create auth file
      copy: src=/etc/ansible/conf/rsync_conf/rsync.password dest=/etc/ mode=600
    • name: step05:create backup dir
      file: dest=/backup state=directory owner=rsync group=rsync
    • name: step06:boot rsync server
      shell: rsync --daemon creates=/var/run/rsyncd.pid
  • hosts: 172.16.1.31
    tasks:
    • name: step01:create auth file
      copy: src=/etc/ansible/conf/rsync_conf/rsync_client.password dest=/etc/rsync.password mode=600
      执行脚本方法:(注意:-C表示模拟执行)
      ansible-playbook /etc/ansible/ansible-playbook/test.yaml
      ansible-playbook -C /etc/ansible/ansible-playbook/test.yaml