'run ansible role with specific playbook
I have one ansible role with this structure:
── prepare-workstation.yaml
── group_vars
└── roles
├── build-nginx-proxy
│ ├── defaults
│ ├── tasks
│ └── templates
│ └── nginx.yml
│
├── ca
│ ├── defaults
│ ├── handlers
│ ├── tasks
│ └── templates
and prepare-workstation.yaml content is:
---
- name: Prepare workstation
hosts:
- workstation
roles:
- { role: ca}
- { role: build-nginx-proxy }
I want build-nginx-proxy role run with nginx.yml not tasks/main.yml.
how can I pass index.yml to build-nginx-proxy role?
something like this:
---
- name: Prepare workstation
hosts:
- workstation
roles:
- { role: ca}
- { role: build-nginx-proxy, 'nginx.yml' }
Solution 1:[1]
Try this
#if nignx.yml is placed in build-nginx-proxy/tasks/nignx.yml
- name: Run tasks/nignx.yaml instead of 'build-nginx-proxy'
include_role:
name: build-nginx-proxy
tasks_from: nignx.yml
or try include_tasks
- name: Include tasks from /roles/build-nginx-proxy/tasks/nignx.yml
include_tasks: /roles/build-nginx-proxy/tasks/nignx.yml
here is the roles documentation
Solution 2:[2]
if you want something parametric, use a local var:
roles:
- role: ca
- role: build-nginx-proxy
vars:
mod: ../nginx.yml
and in main.yml, you do
- include_tasks: "{{ mod }}"
its better to put the task nginx.yml in folder tasks, no need to add ../
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KrishnaR |
| Solution 2 | Frenchy |
