ansible: include role in a role?

后端 未结 3 1259
我寻月下人不归
我寻月下人不归 2021-02-01 00:10

Is it possible to reuse a role in a role? I do not mean via defining a dependency in the meta/main.yml file of a role but by including the role in the tasks/mai

3条回答
  •  广开言路
    2021-02-01 00:44

    AFAIK, you can't. This is what dependencies are for.

    If you want to avoid dependencies (because, for instance, you want 'role X' to run between two tasks), you can do this in the playbook itself if you think the tasks are related :

    roles/webtier/tasks/main.yml:

    - shell: echo 'hello'
    - include: webtier.yml
    - shell: echo 'role done'
    

    All in all, it depends on what you're trying to do exactly. But in your example, 'still busy' seems to imply that the rolebooks/some_role is still running, which is not possible (there is no concurrency here).

    Obviously, you can also sequence roles in a master playbook (which is probably what you do already) :

    - name: Polite foo stuff
      hosts: foo_hosts
      roles:
        - say_hello
        - rolebooks/some_role
        - say_bye
    
    - name: Unpolite foo stuff
      hosts: !foo_hosts
      roles:
        - rolebooks/some_role
    

提交回复
热议问题