ansible: include role in a role?

后端 未结 3 1306
我寻月下人不归
我寻月下人不归 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:50

    You can't, but you can do something kind of similar.

    For a layout of:

    roles/
        ...
        common/tasks/main.yml
        nginx/tasks/main.yml
        ...
    

    In nginx/tasks/main.yml, you can call your common task:

    - name: Call the 'common' role to do some general setup
      include: ../../common/tasks/main.yml
    

    Note that because you're not using the typical import structure, you might run into some "weirdness" like role default variables not being accessible unless you included the role in the standard fashion earlier.

提交回复
热议问题