I'm trying to store ssh private keys in variables in a vault-protected file, and I'm having problems. The issue is with the variables spanning many lines, when they are injected during the playbook run, on the destination server they end up in a mangled format or the playbook crashes out. So for example, in my vars file (this is a key I just generated and deleted to demo it here):
id_dsa: "-----BEGIN DSA PRIVATE KEY-----
MIIBuwIBAAKBgQC4ZqbQspFVSqjJmLbyve+5/NG0oGLa6GMd3pctilZkUcyld/k+
j07TROjQLsSbDiweUa5HKBVSTuoHSLAq7V8vr3DSV2T/bX325STgo/0vkIJeZmcr
1eZiBQyPRMtbVORxbfBI94ofL52C381eRxNhNgr27FUxJPaP0AelmrNtHwIVAI4R
MwoEbRbqBFzwC1lPvV4XrkU3AoGANSGsM0gWzFDUL3o3KpKbGehfAXdKDjGms3FN
r9itrMVy1klErQ9GHOeyGRD+Pkr4LDP7CUELpR58/Yv9358tkkffSpHqstuvgX1k\n
I12214Wk/VqjOBaQhZDa6FwM3wrPAztGAZChvj5BdRQDqh77x9ljBWE8psfZ+TRe
SBvMQ7cCgYAOUWMQdc3RYc/+HuKf8d0ke5ecFXSnpkrNt0spJdviMl0ui8n6aPOy
rP/5FGpzR8to8/xGnpD6RdEFuSTABDHR85Y9pLmts1Zf1ctGMcxXiPsjunHfX/GI
fc6sVh556dgAf7a33aEPjqw7Ll+q9rTq6OFSgL14B1y8Gs2EbyjH6AIVAIQndtm5
YhlFBaJk02PRX3zKorL6
-----END DSA PRIVATE KEY-----"
in my playbook:
- name: push out ssh private keys
shell: 'echo -e "{{ item.value }}" > /home/hcom/.ssh/{{
item.name }}'
with_items:
- { name: "id_dsa", value: "{{ id_dsa }}" }
- { name: "id_rsa", value: "{{ id_rsa }}" }
I've tried adding \n on the end of each line in my key, I've also tried all on one line with \n separators.
I'm getting this error:
fatal: [127.0.0.1] => A variable inserted a new parameter into the module args. Be sure to quote variables if they contain equal signs (for example: "{{var}}").
Any pointers would be cheerfully accepted. I'm interested to hear how others have tackled this issue.
Thanks
Ben