EDIT: I figured it out in the end. Decided to just manually place the master.key on the server in the cap/shared/config and then symbolic link this to each release upon deploy. It works now.
I've setup rails credentials on my production environment. I've put the RAILS_MASTER_KEY into the ubuntu ENV. It's stored in .bashrc and .profile.
In IRB on the server I can type the following command and access the secret key ENV['RAILS_MASTER_KEY]
However when I do my Capistrano deploy it tells me it can't find the secret key.
In my rails app I've edited the /config/environments/production.rb to include:
config.require_master_key = true
Rails.application.credentials.secret_key_base = ENV['RAILS_MASTER_KEY']
But the server won't recognise the secret key.
I am not using DotEnv or Figaro.
Error log below.
ActiveSupport::EncryptedFile::MissingKeyError: Missing encryption key to decrypt file with. Ask your team for your master key and write it to /var/www/appn_name/releases/20190429180042/