Reputation: 435
I am confused with the usage of include_vars
and vars
Example:
- name: "Testing include_vars"
include_vars: "roles/testrole/vars/test.yml"
The above module works, because I think include_vars
is a pre-defined module to include variables from a given file.
The below doesn't work:
- name: "Defining variables locally"
vars:
testvar : "value1"
It throws the following error:
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path
I understand the error that there is no action. But why is there no way to specify variables locally without creating a task. Why a variable has to go with an action - what's the logic or philosophy behind it?
And while it is also possible to set_facts without another action, as set_facts
itself is a module, there is no module to set variables locally. Why?
And if you could also add why there can't be multiple actions added on a single task like: set_facts and shell command in same task?
Upvotes: 0
Views: 458
Reputation: 68104
vars is not a module. It's the declaration of variables. To solve the error add a module to the task. For example debug.
- name: "Defining variables locally"
vars:
testvar: "value1"
debug:
var: testvar
You might want to review the Intro to Playbooks.
To answer your question
Why there is no module to just define variables?
Because of the flexibility. Start planning your architecture with the question "Where does the configuration data come from?". You might want to review the Variable precedence: Where should I put a variable?.
Upvotes: 2