Standing on the shoulders of Giants
hadoop distcp使用filters参数排除指定文件
ansible学习之十:Error Handling In Playbooks
Jul 22, 2014 • ansible
ansible中可以对play
、role
、include
、task
打一个tag(标签),然后:
---
- hosts: 192.168.0.105
tags:
- one #为一个play打tag
tasks:
- name: exec ifconfig
command: /sbin/ifconfig
tags:
- exec_ifconfig #为一个task打tag
---
- hosts: 192.168.0.105
gather_facts: no
tasks:
- include: foo.yml
tags: #方式一
- one
- include: bar.yml tags=two #方式二
上面两种打tag的方式都可以,此时:
ansible-playbook test.yml #执行foo.yml和bar.yml
ansible-playbook test.yml -t one #只执行foo.yml
ansible-playbook test.yml -t two #只执行bar.yml
---
- hosts: 192.168.0.105
gather_facts: no
tasks:
- include: foo.yml tags=one,two
- include: bar.yml tags=two
可以对同一对象打多个tag,只要-t
指定了其中一个tag,就会执行该对象:
ansible-playbook test.yml #执行foo.yml和bar.yml
ansible-playbook test.yml -t one #只执行foo.yml
ansible-playbook test.yml -t two #因为两个include都有two这个标签,所以foo.yml和bar.yml都会执行
---
- hosts: 192.168.0.105
gather_facts: no
roles:
- {role: foo, tags: one}
- {role: bar, tags: [one,two]} #同时对bar打两个tag
则:
ansible-playbook test.yml #执行foo和bar两个role
ansible-playbook test.yml -t two #只执行bar
ansible-playbook test.yml -t one #两个role都有one标签,所以foo和bar都会执行
---
- hosts: 192.168.0.105
gather_facts: no
tasks:
- name: exec ifconfig
command: /sbin/ifconfig
tags:
- exec_cmd
- name: exec ls
command: /bin/ls
tags:
- exec_cmd
- name: debug_test one
debug: msg="test1"
tags:
- debug_test
- name: debug_test two
debug: msg="test2"
tags:
- debug_test
如上面,可以把执行command模块的task都打上exec_cmd
标签,则:
ansible-playbook test1.yml #执行所有tasks
ansible-playbook test1.yml -t exec_cmd #只执行tag为exec_cmd的tasks
下一篇:ansible学习之十:Error Handling In Playbooks