zoukankan      html  css  js  c++  java
  • ansible-playbook的应用实例

    mkdir  /root/test/

    vim  /root/test/test1.yaml

    添加:

    ---
    - hosts: 39.107.103.225          //  第一个任务
    gather_facts: False                  //不读取对方主机的信息
    tags:                                          //主机标签一
    - play1
    tasks:
    - name: create user
    user: name={{ item }}
    with_items:
    - lisi
    - zhangsan
    - wangwu
    - hosts: 39.107.103.225                 //第二个任务
    tags:                                                 //第二个主机标签
    - play2
    tasks:
    - name: create directory
    file: path=/root/{{ item.a1 }} owner={{ item.a2 }} group={{ item.a3 }} mode={{ item.a4 }} state=directory
    with_items:
    - {a1: "benet",a2: "zhangsan",a3: "lisi",a4: "0700"}
    - {a1: "accp",a2: "wangwu",a3: "zhangsan",a4: "0755"}
    - {a1: "yun",a2: "lisi",a3: "root",a4: "0777"}
    - hosts: 39.107.103.225                          //第三个任务
    tags:                                                          //第三个主机标签
    - play3 
    tasks:
    - name: web stie
    file: path=/root/benet/{{ item[0] }}/{{ item[1] }} state=directory
    with_nested:
    - ['benetcom','accpcom','yuncom']
    - ['xixi','haha','lala']
    - hosts: 39.107.103.225                              //第四个任务

    tags:                                                              //第四个主机标签
    - play4
    tasks:
    - name: ipv4
    lineinfile:
    dest: /root/accp/lpc.conf
    line: "{{ item }}"
    with_items:
    - "net.ipv4.conf.all.send_redirects = 0"
    - "net.ipv4.conf.default.send_redirects = 0"
    - "net.ipv4.conf.eth0.send_redirects = 0"
    - hosts: 39.107.103.225                                  //第五个任务

    tags:                                                                  //第五个主机标签
    - play5
    tasks:
    - name: copy txt
    copy: src={{ item }} dest=/root/accp/
    with_fileglob:
    - /root/*.txt
    - hosts: 39.107.103.225                                 //第六个任务
    tags:                                                                 //第六个主机标签
    - play6
    tasks:
    - name: redhat vim
    yum: name=vim-enhanced state=installed
    when: ansible_os_family == "RedHat"
    - name: debian
    apt: name=vim state=installed
    when: ansible_os_family == "Debian"
    - hosts: 39.107.103.225                               //第七个任务
    tags:                                                                //第七个主机标签
    - play7
    tasks:
    - name: panduan
    command: echo {{ item }}
    with_items: [ 0,2,4,6,8,10 ]
    when: item < 5

     

     执行这个命令:

    ansible-playbook  /root/test/test1.yaml

     

     

     

  • 相关阅读:
    【转】PowerDesigner数据库视图同时显示Code和Name
    [转]BT原理分析
    异常机制及throw与throws的区别(转)
    BS与CS的联系与区别。
    ASP.NET和C#的区别/
    上百例Silverlight网站及演示汇总,供友参考
    Bing Maps进阶系列九:使用MapCruncher进行地图切片并集成进Bing Maps
    【Silverlight】Bing Maps学习系列(八):使用Bing Maps Silverlight Control加载自己部署的Google Maps
    学习MAP 地图好地址
    Bing必应地图中国API
  • 原文地址:https://www.cnblogs.com/Leonardo-li/p/8589645.html
Copyright © 2011-2022 走看看