Subject: [ansible-devel] import_playbook - Passing variables - error


I have a playbook called:  *testing_vars_pass.yml*

It imports another playbook called:  *testing_vars_call.yml*

The playbook *testing_vars_call.yml*  expects a variable called:  *myVar*
Below is the contents of each playbook ...

$ cat *testing_vars_pass.yml*
---
- name: Test pass vars
  hosts: all
  vars:
     myVar: hello

  tasks:

  - name: Debug pass vars
    debug:
      msg: "{{ myVar }}"

- import_playbook: *testing_vars_call.yml* myVar="{{ myVar }}"
        ... and ...
$ cat *testing_vars_call.yml*
---
- name: Test call vars
  hosts: all
  vars:
    myVar: = "{{ myVar }}"

  tasks:

  - name: Debug call vars
    debug:
      msg: "{{ myVar }}"

This produces the following error ...

18 TASK [Debug call vars]
*********************************************************

19 fatal: [1.1.1.1]: FAILED! => {"msg": "An unhandled exception occurred
while templating '{{ myVar }}'. Error was a <class
'ansible.errors.AnsibleError'>, original message: An unhandled exception
occurred while templating '{{ myVar }}'.  [...]

The same error is seen if I use the syntax ...

- import_playbook: testing_vars_call.yml
  vars:
    myVar:  "{{ myOwnVar }}"

In case the fact that the 'myVars' variable had the same name in both
playbooks, I changed the name in the first playbook ...

$ cat *testing_vars_pass.yml*
---
- name: Test pass vars
  hosts: all
  vars:
     my*Own*Var: hello

  tasks:

  - name: Debug pass vars
    debug:
      msg: "{{ my*Own*Var }}"

- import_playbook: testing_vars_call.yml myVar="{{ my*Own*Var }}"
This time, I get a different error ...

18 TASK [Debug call vars]
*********************************************************

19 fatal: [1.1.1.1]: FAILED! => {"msg": "The task includes an option with
an undefined variable. The error was: 'myOwnVar' is undefined\n\nThe error
appears to have been in
'/var/lib/awx/projects/_6__unix/testing_vars_call.yml': line 9, column 5,
but may\nbe elsewhere in the file depending on the exact syntax
problem.\n\nThe offending line appears to be:\n\n\n  - name: Debug call
vars\n    ^ here\n"}
What is the correct way to pass variables into playbooks via
'import_playbook'?

--