skip to Main Content

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' }    

2

Answers


  1. 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 ../

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search