I like to use WSL to execute Ansible scripts on remote hosts. The benefits, IMHO, are that you can develop them on your usual Windows system and there's no need for a special VM, network mount or something else to be able to run them on a target system. As I'm a lazy person π, I don't want to enter my Ansible vault encryption key and my ssh key every time I try executing an ansible playbook (there's much of development and testing going on here). Not only lazy, but also a little paranoid, still I don't want to have my plain text passwords stored permanently in my file system. Especially regarding SSH keys used with ssh-agent, WSL will put some obstacles in your way you wouldn't have to face on a "real" Linux system.
This script will therefore benefit my lazyness and paranoia and also overcome the hinderance imposed by WSL. π
Place the script anywhere you find appropriate. For now, we will assume it is in your home directory and called wsl_ansible_preparations.sh. Don't forget to make it executable using chmod u+x ~/wsl_ansible_preparations.sh.
In the beginning of the script file, there are five variables defined. You might possibly want to adapt at least the first one. :) (The file contains comments about the meanings of the variables.)
Most important now: Add this script to your .profile in order for it to be executed when you exit the WSL shell. Example line:
trap ${HOME}/wsl_ansible_preparations.sh EXITThis will call the script without parameters and hence just delete the files containing sensitive data (if present). If you're as paranoid as I am, you might also want to call the script in your .bashrc. π (Just the "pure" script call in that case, no trap nor EXIT.)
After these preparations, to enter your passwords, just call the script and append the parameter denoted in PARAMETER_FOR_SECRET_INPUT (default: login).
~/wsl_ansible_preparations.sh loginYou will the be asked for your ansible vault and ssh key passwords. These will be saved (the first in the file denoted by ANSIBLE_VAULT_PASSWORD_FILE, default: ~/ansibleVaultPassword), the latter using ssh-agent.
Now, when executing an ansible playbook like this
ansible-playbook myplaybook.yml --vault-password-file ~/.ansibleVaultPassword --private-key ~/.ssh/ansible.private.pemyou won't be asked for a password any more until the end of your WSL session or ssh-agent timeout. π
No problem, just execute the script again:
~/wsl_ansible_preparations.sh loginI've tried to write the script in a comprehensible, concise and secure way. Nevertheless, I cannot guarantee that the script will work on your system! Furthermore, I even cannot ensure that it isn't harmful to your system or the security of your data! The script is free software. It comes without any warranty, not even for merchantability or fitness for a particular purpose. Modify and/or use it on your own risk.