Pass variable to inclusion in playlist?

I would like to have a master book that includes other playbooks. Is it possible to pass a variable into what a playbook includes?

The normal syntax that is used to pass variables to included tasks does not work (see below)

- include: someplaybook.yml variable=value 

and

 - include: someplaybook.yml vars: variable: value 

I am running v2.0.2.0.

+6
source share
2 answers

The only thing I see is quotes.

 - include: someplaybook.yml variable='value' 

It works for me and should work for you too. If you do not report an error that you encounter.

Make sure that this variable is "variable" defined in the task of this role, and from here you simply pass the value of this variable.

0
source

In addition, I suggest you read this, http://docs.ansible.com/ansible/latest/playbooks_reuse.html and try to use roles in this case, this will help in this case when you are trying to enable / import several players into one main book. And about passing the value to the include statement, you can add it to the vars main.yml roles. Or, if the variable you want to pass is the result of the previous task in one main play, use "register" and save the output in the variable.

- debug: msg="{{result.stdout_lines}}"

here, the result is a registered variable. Use the debugging module to know exactly what you want to transfer to the playbook. Hope this helps.

0
source

All Articles