Haryvar
Haryvar

Reputation: 23

Ansible can't run when vars are used in include_tasks

I have two playbooks driver.yaml invoking another play after converting from template called main_driver.yml

Main playbook driver.yml

---
- name: Setup Services
  hosts: all
  gather_facts: no
  vars_files:
    - var_input_driver.yaml

  tasks:
    - name: Converting template to playbook
      template:
         src: template_for_driver.yaml.j2
         dest: main_driver.yaml
      delegate_to: localhost

    - name: run roles
      include_tasks: main_driver.yaml

Content of main_driver.yaml

---
- name: Setup Services
  vars:
    java_package: java-11-openjdk
    dock_version: 18.09.0

- name: Setup services
  include_role:
    name: configure-java

Receiving error as below:

FAILED! => {"reason": "no module/action detected in task.\n\nThe error appears to be in 'main_driver.yaml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Setup Services\n ^ here\n"}

Upvotes: 0

Views: 1897

Answers (2)

Zeitounator
Zeitounator

Reputation: 44605

vars is not a module name but a task option. You should fix your included file like so:

---
- name: Setup services
  include_role:
    name: configure-java
  vars:
    java_package: java-11-openjdk
    dock_version: 18.09.0

An other possible way would be:

---
- name: Set variables
  set_fact:
    java_package: java-11-openjdk
    dock_version: 18.09.0

- name: Setup services
  include_role:
    name: configure-java

Upvotes: 1

Trondh
Trondh

Reputation: 3341

couple of things:

  • main_driver.yaml seems to include itself (main_driver) - that probably won't work.
  • the task file used with "include_tasks" should be a "pure" task file, not a playbook. In other words, it should not contain a playbook header (hosts, name, etc), but simply a list of tasks.

Im struggling to understand the logic in your example, maybe double-check that the file contents are correct?

Upvotes: 0

Related Questions