Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to pull a build from S3 on my target machine. Therefore I need to pass the S3 key and secret to the ansible playbook somehow.

I know that I could define them in

  • the inventory
  • the playbook itself

but I really don't want to store credentials there.

Can I use environment variables from the local machine (or something similar) in an ansible playbook?

share|improve this question
up vote 5 down vote accepted

$ENV(SOMEVAR) or {{ lookup('env', 'SOMEVAR') }} (1.1+) should work. You could also use vars_prompt to request it at playbook runtime.

share|improve this answer

Check out ansible-vault it allows you to encrypt variables into a file and then "unlock" that file at run-time.

Failing that, you can also specify extra variables at runtime with the -e "" flag:

ansible-playbook -i inv/production myplaybook.yml -e "s3_key=<value here> s3_secret=<secret here>"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.