请问 Ansible tag 在role中不能生效

/roles/test/tasks/main.yml

---
- name: deploy
  debug: msg="This is an install method."
  tags:
    - deploy

- name: uninstall
  debug: msg="test uninstall section."
  tags: 
    - uninstall

/site.yml

---
- hosts: localhost
  gather_facts: no
  tasks:
    - name: loading role
      include_role:
        name: test
        tags: deploy

运行

ansible-playbook site.yml

结果是:

PLAY [localhost] ***************************************************************************************************************

TASK [test : deploy] ***********************************************************************************************************
ok: [localhost] => {
    "msg": "This is a install method."
}

TASK [test : uninstall] ********************************************************************************************************
ok: [localhost] => {
    "msg": "test uninstall section."
}

PLAY RECAP *********************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0

我觉得写的没错的话,应该是仅仅运行deploy那个任务的,为啥所有的任务都运行了?

阅读 4.5k
2 个回答

你这个只是对task进行打标签的操作,不行.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进