#2192·capistrano

How to wrap capistrano commands with a custom script to support secrets manager?

Author: mmustalaCreated Aug 9, 2026Updated Aug 9, 2026

I'm taking Bitwarden into use, and Capistrano deploys are the last bit to update.

The bws run command inserts the configured environment from Bitwarden into the running process.

I have a wrapper script in /usr/local/bin/with-bitwarden

#!/bin/bash
exec /usr/local/bin/bws run -- "$@"

And would need to tell Capistrano to use it with all the rake and rails commands. So bundle exec rake assets:precompile becomes bundle exec with-bitwarden rake assets:precompile

ChatGPT suggested adding this mapping, but Capistrano doesn't seem to be using it.

SSHKit.config.command_map[:rake] = "with-bitwarden bundle exec rake"
SSHKit.config.command_map[:rails] = "with-bitwarden bundle exec rails"

Currently using Capistrano 3.20.1

The actual error that is happening now is below. Happening because the RAILS_MASTER_KEY is not set, and there is no master.key file either.

deploy:assets:precompile
      01 /home/nordic_connector//rvm1scripts/rvm-auto.sh . bundle exec rake assets:precompile
      01 rake aborted!
      01 NoMethodError: undefined method '[]' for nil (NoMethodError)
      01
      01   config.active_record.encryption.primary_key = Rails.application.credentials[:active_record_encryption][:primary_key]