import_playbook and variables

I have a playbook.yml that has several import_playbook statements, like this

  • import_playbook: plays/prepare.yml

  • import_playbook: plays/vpn_server.yml

  • import_playbook: plays/web_server.yml

and so on.

I want the first playbook to load some project configuration/facts//variables that should be available to all other playbooks.

I noticed however that the variable set is unique to each playbook. Unless I am doing sth wrong.

Can I somehow have this organization in my playbook.yml? Some ‘hacky’ thoughts I had about this were to “return” an all_vars hash/dict from the first playbook that then I would pass to the others. Or before all the import_playbook statements, actually have a play that will produce the variables and then pass them to the next ones. Note that the variables are a lot and passing them all one by one to each playbook would be ugly and not viable.

This was my misunderstanding of how Ansible uses variables. The variables are not unique to each playbook as I wrote, but to each host.