Include task from different playbook

450 views
Skip to first unread message

Jugal Porwal

unread,
Sep 30, 2015, 10:21:54 AM9/30/15
to Ansible Project
Hi,

I'm trying to include a play from different play book. The structure is as follows:

---
- hosts: localhost
  vars_files:
      - /etc/ansible/parent/parent.yml
  tasks:
    - name: Template the component properties files
      template:
        src=/etc/ansible/templates/{{item}}.j2
        dest=/etc/ansible/templates/{{item}}/service-container.properties
      with_items:
        - [ 'router',  'report-scheduler', 'WH-Payload-Processor']

  tasks:
    - include: /etc/ansible/playbooks/wrapper.yml

---
- hosts: localhost
  tasks:
    - name: Template the wrapper.conf file
      template:
        src=/etc/ansible/templates/wrapper.j2
        dest=/etc/ansible/templates/router/wrapper.conf
      vars:
        - serviceName: router

However i get the error "no task detected". what is the issue here?

=>Also is this feasible:

---
- hosts: localhost
  vars_files:
      - /etc/ansible/parent/parent.yml
  tasks:
    - name: Template the component properties files
      template:
        src=/etc/ansible/templates/{{item}}.j2
        dest=/etc/ansible/templates/{{item}}/service-container.properties
      with_items:
        - [ 'router',  'report-scheduler', 'WH-Payload-Processor']

  tasks:
    - include: /etc/ansible/playbooks/wrapper.yml  some_var={{item}}
      with_items
           - router
           - gateway
           - resource

---
- hosts: localhost
  tasks:
    - name: Template the wrapper.conf file
      template:
        src=/etc/ansible/templates/wrapper.j2
        dest=/etc/ansible/templates/{{item}}/wrapper.conf
      vars:
        - serviceName: {{item}}

J Hawkesworth

unread,
Sep 30, 2015, 10:54:03 AM9/30/15
to Ansible Project
Looks like you are attempting to include a playbook.

You probably want to use pre_tasks instead of tasks for the first part to ensure things run in the order you want too.  This would like something like the following:

---
- hosts: localhost
  vars_files:
      - /etc/ansible/parent/parent.yml
  pre_tasks:

    - name: Template the component properties files
      template:
        src=/etc/ansible/templates/{{item}}.j2
        dest=/etc/ansible/templates/{{item}}/service-container.properties
      with_items:
        - [ 'router',  'report-scheduler', 'WH-Payload-Processor']

 - include: /etc/ansible/playbooks/wrapper.yml 

Jugal Porwal

unread,
Oct 1, 2015, 1:07:09 AM10/1/15
to Ansible Project
it still gives the same error . "no action detected in task" is there any alternative way to do it?

Jugal Porwal

unread,
Oct 1, 2015, 1:29:17 AM10/1/15
to Ansible Project
The included files need not contain the hosts and the tasks modules. It works for the below file :

---

    - name: Template the wrapper.conf file
      template:
        src=/etc/ansible/templates/
wrapper.j2
Reply all
Reply to author
Forward
0 new messages