【无标题】

Ansibel中的Playbook

1. 理解
相当于一种剧本,其中有多条要执行的命令。
2. 变量
全局变量:在命令后面-e添加变量为全局变量。
资产变量:在资产中生命的变量
剧本变量:在playbook中声明的变量
系统中的facts变量
优先级:
全局变量 > 资产变量> 剧本变量>facts变量
3. 控制循环
with_item:控制变量循环
item:固定变量名称,不可变
4. 判断,控制变量
在命令后用 关键字 when 变量名==参数值 来控制判断条件。
5. tags 标签
命令后加-t 用来标志,执行时只执行在playbook中用tags标记过的命令
6. handlers
handler与notify共同使用:例如:

- name: test.yml just for test  
  hosts: testserver  
  vars:    
      region: ap-southeast-1  
  tasks:    
      - name: template configuration
        file      template: src=template.j2 dest=/etc/foo.conf      
  notify:          
      - restart memcached          
      - restart apache  
  handlers:    
        - name: restart memcached      
          service: name=memcached state=restarted    
        - name: restart apache      
          service: name=apache state=restarted

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值