There are 20+ ways to create variables in Ansible, such as on the command line, in a playbook, or from a file, just to name a few. Following are common ways that variables can be created. This list is in the order of precedence, where the option higher in the list takes precedence over options lower in the list.
Let's say you have a variable defined twice. For example, let's say the foo variable is defined in the vars plugin and contains a value of Hello.
--- - hosts: all vars: foo: "Hello"
Let's also say that the --extra-vars command line option is being used to set the foo variable to contain a value of World.
ansible-playbook example.yml --extra-vars "foo=World"
In this scenario, the foo variable would contain a value of World, because the --extra-vars command line option takes precedence over the vars plugin.