Ansible。将前/后任务分配到playbook中的标签

时间:2017-09-27 12:56:06

标签: ansible

我用下一个方式在最终剧本中描述了我的标签:

  roles:
    - { role: common, tags: ["common"] }
    - { role: redis, tags: ["redis"] }

除了在同一剧本中,我还有前/后任务部分:

  pre_tasks:
    - include: pre_post_tasks/create_lock.yml

  post_tasks:
    - include: pre_post_tasks/remove_lock.yml

问题是前/后任务仅在包含所有标签的情况下启动(无标签参数):

ansible-playbook -vv -l host -i inventory/dev --extra-vars '@temporary/additional_inventory' playbook.yml

不要使用标签:

ansible-playbook -vv -l host -i inventory/dev --extra-vars '@temporary/additional_inventory' playbook.yml --tags "redis"

为什么呢?它是按设计的吗?怎么避免这个?我想在所有情况下执行前/后任务。

1 个答案:

答案 0 :(得分:5)

与所有任务一样,您可以使用special tags。在您的情况下always

pre_tasks:
  - include: pre_post_tasks/create_lock.yml
    tags:
      - always

post_tasks:
  - include: pre_post_tasks/remove_lock.yml
    tags:
      - always