How can I pass variable to ansible playbook in the command line?

It is possible to set variables at the command line using the –extra-vars (or -e) argument. Variables can be defined using a single quoted string (containing one or more variables) using one of the formats below.

key=value

Method 1

Method 2
An alternative to using command line args is to utilise environmental variables that are already defined within your session, you can reference these within your ansible yml files like this:

Method 3
If you are passing variables from a file, you need a second –extra-vars flag to pass variables.

Method 4
How can I pass yaml array to –extra-vars in Ansible playbook?

To answer your first question “How can I pass yaml array to –extra-vars in Ansible playbook.” you can pass in a json formatted string to extra-vars.

Here is an example play:

Method 5 – PASSING MULTIPLE VARIABLES.

Reference
https://docs.ansible.com/ansible/2.5/user_guide/playbooks_variables.html#passing-variables-on-the-command-line

https://ttl255.com/ansible-pass-extra-variables-to-playbook/