Here is the workflow I want to achieve:
The first 2 steps working fine, but here is the problem: How/Where should I store my private keys to allow ansible to ssh to my remote server via ssh agent?
I am a bit reluctant to store the private key inside Pipeline env settings, since everyone else has admin access to the repo can see it.
There is a similar question asked here but the answer suggests to setup the keys on docker and use private repo, which it's a bit different to mine.
You can now setup SSH keys under pipeline settings so that you do not need to use environment variables and copy to certain locations in the container. The private key is not shown at all.
Under
Settings -> Pipelines -> SSH keys
You would need to get the public key to the production containers known_hosts file.
I have set up a similar process and used Pipelines environment variables, there is a checkbox to secure the value so you don't need to worry about others viewing it.
The set up is pretty easy:
Then in your bitbucket-pipelines.yml file set up the known_hosts and key:
- mkdir -p ~/.ssh
- cat my_known_hosts >> ~/.ssh/known_hosts
- (umask 077 ; echo $MY_SSH_KEY | base64 --decode > ~/.ssh/id_rsa)
Full documentation is available here https://confluence.atlassian.com/bitbucket/access-remote-hosts-via-ssh-847452940.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With