include tasks from another role in ansible playbook

前端 未结 3 1383
我在风中等你
我在风中等你 2021-01-30 09:57

I\'m designing a kind of playbook lib with individual tasks

so in the usual roles repo, I have something like:

roles
├── common
│   └── tasks
│       ├──         


        
3条回答
  •  感动是毒
    2021-01-30 10:45

    Yes, Ansible doesn't really like tasks as individual components. I think it wants you to use roles, but I can see why you wouldn't want to use roles for simple, reusable tasks.

    I currently see two possible solutions:

    1. Make those task-files into roles and use dependencies

    Then you could do something like this in e.g. custom_stuff_workflow

    dependencies:
      - { role: login }
    

    See: https://docs.ansible.com/playbooks_roles.html#role-dependencies

    2. Use include with "hardcoded" paths to the task files

    - include: ../../common/tasks/login.yml
    

    That worked pretty well in a short test playbook I just did. Keep in mind, you can also use parameters etc. in those includes.

    See: http://docs.ansible.com/ansible/latest/playbooks_reuse.html

    I hope I understood that question correctly and this helps.

提交回复
热议问题