I wrote here already an introduction to Ansible. In Ansible you have roles and playbooks. A playbook can contain several roles. Inside a role you can have tasks, files, handlers and variables. But sometimes you want to use a variable across multiple roles. Unfortunately Ansible doesn’t have really a concept of global vars, but there is a trick 😉
You can define group variables for ALL groups, that is indeed like a global variable. I manage my Ansible code in a git repo. The file tree looks like this:
The variables defined in “group_vars/all/vars.yml” are accessible from ALL roles!