我被要求为预生产和生产服务器编写两个角色,这些角色将安装一些程序(Memcached,它的PHP扩展等),并且还配置它们。
好吧,昨天,我搞砸了一下,因为还有另外两个角色被使用,而我的还没有完成。昨天,我们团队正在开展的项目已投入生产。在每个上面,Playbook都会运行,其中包含所有角色,它也开始运行我的角色。幸运的是,我的团队主管准时看到了它并从剧本中删除了我的角色。
所以在这里看看我在删除之前在剧本中的角色:
- hosts: was
roles:
- { role: cron, become: yes, tags: [ was, cron ] }
- { role: app, when: type == 'master', become: yes, become_user: "{{become_user}}", become_flags: '-i', tags: [ was ] }
- { role: memcacheExtension, become: yes, become_user: ansible, tags: ['memcache'] }
- { role: gitlabRunner, become: yes, become_user: "{{become_user}}", tags: ['gitlab'] }
我的角色是最后两个角色。我认为使用这种配置,只有在命令运行时使用我设置的标签之一才会触发它们。剧透:我错了。
我听说过'never'标签,但它只适用于tasks
,所以我必须为每个任务设置它,这不是我想要的。
还有其他可能性吗?
先感谢您
是的,有可能import_role,或include_role这是一项任务,可以标记。
- hosts: was
roles:
- { role: cron, become: yes, tags: [ was, cron ] }
- { role: app, when: type == 'master', become: yes, become_user: "{{become_user}}", become_flags: '-i', tags: [ was ] }
tasks:
- import_role:
name: memcacheExtension
become: yes
become_user: ansible
tags: memcache
- import_role:
name: gitlabRunner
become: yes
become_user: "{{become_user}}"
tags: gitlab