zoukankan      html  css  js  c++  java
  • ansible变量定义

    一./etc/ansible/hosts

    [webServers]
    192.168.2.100 http_port=8080
    192.168.2.200 http_port=8009

    [web]
    web1
    web2

    [db]
    db1
    db2

    [app:children]
    web
    db

    二./etc/ansible/hosts

    [webServers]
    192.168.2.100 
    192.168.2.200 
    [webServers:vars]
    name=nginx

    三.playbook中定义

    - hosts: test
      remote_user: root
      vars:
        - path: /usr/local/nginx/sbin/nginx
        - var2: value2

    四.命令行指定

    [root@L ansible]# ansible-playbook -e 'http_port=80 name=nginx' test.yaml

    五.独立文件

    [root@L ansible]# vim vars.yaml
    var1: httpd
    var2: vsftpd
    ---
    - hosts: test
      remote_user: root
      vars_files:
        vars.yaml
    
      tasks:
        - name: install httpd
          yum : name={{ var1 }}

     六.嵌套子变量

    ---
    - hosts: test
      remote_user: root
    
    
      tasks:
        - name: create user
          user: name={{ item.name }} group={{ item.group }}
           with_items:
                - { name: 'user1' , group: 'group1}
                - { name: 'user1' , group: 'group1}        
  • 相关阅读:
    谁的朱砂痣染白了谁的白月光
    随机数
    常见面试简单汇总整理
    oss分页列举遍历文件创建软链接
    oss创建软链接
    看英文文档的好处
    js原型链相关
    js 中的this指向问题
    jquery.fn.init
    转载
  • 原文地址:https://www.cnblogs.com/ray-mmss/p/10176015.html
Copyright © 2011-2022 走看看