using variables defined in files when running ansible command?

106 views
Skip to first unread message

Makson Lee

unread,
Oct 20, 2016, 1:01:30 PM10/20/16
to Ansible Project
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?

$ ansible group1 -a "echo hello" -e "vars_files=secrets.yml"
host1 | FAILED | rc=0 >>
the field 'become_pass' has an invalid value, which appears to include a variable that is undefined. The error was: 'admin_pass' is undefined

Kai Stian Olstad

unread,
Oct 20, 2016, 1:42:16 PM10/20/16
to ansible...@googlegroups.com
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).


--
Kai Stian Olstad

Makson Lee

unread,
Oct 20, 2016, 7:32:25 PM10/20/16
to Ansible Project, ansible-pr...@olstad.com
On Friday, October 21, 2016 at 1:42:16 AM UTC+8, Kai Stian Olstad wrote:
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.
Reply all
Reply to author
Forward
0 new messages