# using variables defined in files when running ansible command?

**URL:** <https://forum.ansible.com/t/using-variables-defined-in-files-when-running-ansible-command/22840>\
**Category:** Ansible Project\
**Created:** [October 20, 2016, 6:06am UTC](https://forum.ansible.com/t/using-variables-defined-in-files-when-running-ansible-command/22840 "2016-10-20T06:06:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Makson\_Lee](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Makson\_Lee](https://forum.ansible.com/u/Makson_Lee)\
**Post date:** [October 20, 2016, 6:06am UTC](https://forum.ansible.com/t/using-variables-defined-in-files-when-running-ansible-command/22840/1 "2016-10-20T06:06:03Z")

</div>

here is the content of inventory file, admin\_pass is defined in secrets.yml file,

> [group1]  
> host1  
> [group1:vars]  
> ansible\_become\_pass={{admin\_pass}}

the question is, how to reference variables defined in a file when running ansible command? we tried the following but didn’t work, can someone help?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 20, 2016, 5:41pm UTC](https://forum.ansible.com/t/using-variables-defined-in-files-when-running-ansible-command/22840/2 "2016-10-20T17:41:44Z")

</div>

Copy paste from "man ansible"

-e EXTRA\_VARS, --extra-vars='EXTRA\_VARS  
Extra variables to inject into a playbook, in key=value key=value format or as quoted YAML/JSON (hashes and arrays). To load variables from a file, specify the file preceded by @ (e.g. @vars.yml).

---

<div class="post-metadata">

**Author:** ![Makson\_Lee](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Makson\_Lee](https://forum.ansible.com/u/Makson_Lee)\
**Post date:** [October 20, 2016, 11:32pm UTC](https://forum.ansible.com/t/using-variables-defined-in-files-when-running-ansible-command/22840/3 "2016-10-20T23:32:24Z")

</div>

> Copy paste from “man ansible”

i only tried “ansible --help” ☹

> -e EXTRA\_VARS, --extra-vars='EXTRA\_VARS  
> Extra variables to inject into a playbook, in key=value key=value format  
> or as quoted YAML/JSON (hashes and arrays). To load variables from a  
> file, specify the file preceded by @ (e.g. @vars.yml).

it works now, thank for your help.
