Setting the private SSH key from variables in a play?

I want to be able to set the path to the private SSH key in a playbook so I don’t need to pass it on the command line all the time.

My use-case is having 10+ AWS accounts for dev/test/prod, etc. with separate keys for each. I’m not using EIPs so I can’t use host vars. Instead, in my plays I pass an ‘environment’ variable that specifies whether I’m in dev01, test02, etc., and variables for the relevant environment get loaded using vars_files (I’m using ansible for provisioning new instances and snapshotting them as AMIs).

I know how to set the SSH user in playbooks, but how can I set the private SSH key path as well?

Mark

Sure!

You can set ansible_ssh_private_keyfile as an inventory variable with the path to your key.

see details here: http://ansibleworks.com/docs/patterns.html#id3

Thanks, I’ll try it.