torlee 发表于 2018-1-2 22:42:18

Ansible之tags介绍

  本节内容:


[*]tags介绍

一、tags介绍
  我们每次改完配置文件,比如上一篇博客中的的apache.yml,没必要把整个playbook都运行一遍,只需要运行改变了的task。我们可以给task一个标签,运行playbook时明确只运行这个标签对应的task就可以了。多个任务可以使用同一个tags。
  如果在某次运行中,我们多次运行同一个playbook,第一次运行时我们期望所有的tasks都运行,第二次运行时我们期望只运行某一个task,你可以给这个task定义一个tags,例如:
  

# vim apache.yml  

- hosts: nginx  
remote_user: root
  
vars:
  

- package: apache  
tasks:
  

- name: install httpd package  

yum: name={{ package }} state=latest  

- name: install configuration file for httpd  
template: src
=/root/conf/httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf  
tags:
  

- conf  
notify:
  

- restart httpd  

- name: start httpd service  
service: enabled
=true name=httpd state=started  
handlers:
  

- name: restart httpd  
service: name
=httpd state=restarted  


  运行:
  

# ansible-playbook apache.yml --tags="conf"  

  如果一个playbook中有多个tags,但是有个tag你不想跑,可以使用--skip-tags。
页: [1]
查看完整版本: Ansible之tags介绍