user4889345
user4889345

Reputation:

Including playbook in a playbook and defining environment file

I have an ansible playbook. When I run the playbook I specify which environment file to use.

ansible-playbook playbooks/release-deploy.yaml -i env/LAB3

Within the ansible-playbook I am calling another playbook and I want the same environment file to be used.

My current config is:

 - include: tasks/replace_configs.yaml

So when I run the playbook, I get the error:

TASK [include] *****************************************************************  
fatal: [10.169.99.70]: FAILED! => {"failed": true, "reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/home/ansible/playbooks/tasks/replace_configs.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- hosts: cac
  ^ here


The error appears to have been in '/home/ansible/playbooks/tasks/replace_configs.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.


The offending line appears to be:

---
- hosts: cac
  ^ here
"}

tasks/replace_configs.yaml also needs to use env/LAB3

Looks like it doesn't know what cac is. Do I need to do another config ?

Upvotes: 0

Views: 171

Answers (1)

techraf
techraf

Reputation: 68499

My current config is:

- include: tasks/replace_configs.yaml

This is not any "config", this is a line which includes a file containing tasks.

Let's look at the following "task":

The offending line appears to be:

---
- hosts: cac
  ^ here

It does not look like a task, it looks like a play. It most likely does not contain any module directive, so Ansible rightfully complains that there is no module name provided in the task it expected: no action detected in task.

When you use include directive in Ansible it puts the included content at the indentation level of the include, so when you include tasks, you should include only tasks

Your included file should look like:

---
- name: This is a task
  debug: msg="One task"

- name: This is another task
  debug: msg="Another task"

and should not contain any other definitions, particularly those belonging to a higher level.

Upvotes: 1

Related Questions