Variable defined in main play is not passed to included playbook

I posted an issue recently on github (https://github.com/ansible/ansible/issues/23394) and was advised to post here on the user list since the issue I am encountering is not a bug. I am re-posting the content here with the response I received.

You could experiment with passing vars to a role.

roles:

  • role: do_things_with_ticket
    ticket_number_to_process: “{{ticket_number}}”

If you have lots of vars you need to set and don’t want to set -e command line for each of them, write them to a file and use the -e @/path/to/some/file.yml to load the extra vars in.
This is pretty much what I do for our nightly integration build. I run one playbook to generate a yaml file containing all the versions of all the software components and then pass the output .yml file to a second playbook that deploys any updates.

You might also be able to use include_vars if you have the vars in a file.

Hope this helps.

Jon