标签

Play 包含几个可以标记的任务:

- name: Install applications
  hosts: all
  become: true
  tasks:
    - name: Install vim
      apt: name=vim state=present
      tags:
        - vim
    - name: Install screen 
      apt: name=screen state=present
      tags:
        - screen

带标签’vim’的任务将在标签中指定’vim’时运行。你可以根据需要指定任意数量的标签。使用’install’或’config’等标签很有用。然后,你可以通过指定标签或跳过标签来运行 playbook。对于

ansible-playbook my_playbook.yml --tags "tag1,tag2"
ansible-playbook my_playbook.yml --tags "tag2"
ansible-playbook my_playbook.yml --skip-tags "tag1"

默认情况下,Ansible 运行所有标签