zoukankan      html  css  js  c++  java
  • 5.ansible 剧本编写规范

    三种规范原则:
    空格: 缩进信息 两个空格
    PS:编写剧本时,将tab键扣掉
    冒号: key-value(键值关系) hosts: 172.16.1.41
    冒号后面不需要有空格情况:
    01. 以冒号结尾
    02. 冒号信息出现在注释信息中
    短横线:- 生成列表信息
    - hosts: 172.16.1.41
    - hosts: 172.16.1.31
    1.编写示例

    cat test.yaml 
    - hosts: 192.168.1.203
      tasks:
        - yum: name=cowsay state=installed
        - copy: src=/etc/hosts dest=/tmp/hosts.bak remote_src=yes
    

    2.语法检查 检查语法有没有错误

    ansible-playbook --syntax-check test.yaml 
    
    playbook: test.yaml
    

    3.剧本模拟执行 检查剧本是否能执行

    ansible-playbook -C  test.yaml 
    
    PLAY [192.168.1.203] ****************************************************************************************************************************************
    
    TASK [Gathering Facts] **************************************************************************************************************************************
    ok: [192.168.1.203]
    
    TASK [yum] **************************************************************************************************************************************************
    changed: [192.168.1.203]
    
    TASK [copy] *************************************************************************************************************************************************
    ok: [192.168.1.203]
    
    PLAY RECAP **************************************************************************************************************************************************
    192.168.1.203              : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
    

    4.剧本执行

    ansible-playbook test.yaml 
    
    PLAY [192.168.1.203] ****************************************************************************************************************************************
    
    TASK [Gathering Facts] **************************************************************************************************************************************
    ok: [192.168.1.203]
    
    TASK [yum] **************************************************************************************************************************************************
    changed: [192.168.1.203]
    
    TASK [copy] *************************************************************************************************************************************************
    ok: [192.168.1.203]
    
    PLAY RECAP **************************************************************************************************************************************************
    192.168.1.203              : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
    

    rsync 示例

    cat rsync.yaml

    - hosts: 172.16.1.41
      tasks:
        - name: 01:install rsync software
          yum: name=rsync state=installed
        - name: 02:push client
          copy: src=./rsyncd.conf dest=/etc/
        - name: 03:create user
          user: name=rsync shell=/sbin/nologin create_home=no
        - 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:重启rsync服务  
          service: name=rsyncd state=restarted enabled=yes   
    
    - hosts: rsync_client
      tasks:
        - name: 01:ceate password file
          copy: content='oldboy123' dest=/etc/rsync.password mode=600
    
  • 相关阅读:
    Python【第五篇】模块、包、常用模块
    Python【第四篇】函数、内置函数、递归、装饰器、生成器和迭代器
    TCP三次握手、四次挥手
    分别用postman和python做post请求接口功能测试
    Python【第三篇】文件操作、字符编码
    Python【第二篇】运算符及优先级、数据类型及常用操作、深浅拷贝
    Python【第一篇】python安装、pip基本用法、变量、输入输出、流程控制、循环
    oracle在windows(含客户端工具pl/sql安装)下安装
    Python【初识篇】简介
    Web jsp开发自学——ajax+servlet+echarts+json+gson 实现ajax传输servlert和echarts的数据,可视化结果
  • 原文地址:https://www.cnblogs.com/yangtao416/p/14592365.html
Copyright © 2011-2022 走看看