Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables set in "deploy.rb" can't be fetched in "staging files" and "task files" #1519

Oliboy50 opened this issue Oct 29, 2015 · 3 comments


Copy link

@Oliboy50 Oliboy50 commented Oct 29, 2015

Everything is in the title.

Since, I didn't find anything about this huge problem, I presume this is due to a mistake on my side.

Here is my whole configuration:

Ubuntu 14.04
foo@bar:~$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
foo@bar:~$ cap -v
Capistrano Version: 3.4.0 (Rake Version: 10.4.2)


set :deploy_config_path, 'capistrano/deploy.rb'
set :stage_config_path, 'capistrano/environments'

require 'capistrano/setup'

require 'capistrano/deploy'

Dir.glob('capistrano/tasks/*.cap').each { |r| import r }


lock '3.4.0'

set :application, 'FooBarProject'
set :keep_releases, 3

set :scm, :git
set :repo_url, ''

set :linked_dirs, fetch(:linked_dirs, []).push('build', 'app/logs', 'web/uploads')
set :linked_files, fetch(:linked_files, []).push('app/config/parameters.yml')


set :stage, :staging

set :ssh_user, 'oliboy25'
set :tmp_dir, -> { "/home/#{fetch(:ssh_user)}/tmp/capistrano" }

set :branch, 'master'
set :deploy_to, -> { "/var/www/html/#{fetch(:application)}" }

server '',
  roles: %w{web app db},
  user: fetch(:ssh_user),
  ssh_options: {
    auth_methods: %w(publickey),
    keys: %w(staging/id_rsa)


desc "Check that we can access everything"
task :check_write_permissions do
  on roles(:all) do |host|
    if test("[ -w #{fetch(:deploy_to)} ]")
      info "#{fetch(:deploy_to)} is writable on #{host}"
      error "#{fetch(:deploy_to)} is not writable on #{host}"

Output (when using task with this configuration)

foo@bar:~$ cap staging check_write_permissions
DEBUG [dba57f80] Running /usr/bin/env [ -w /var/www/html/ ] as
DEBUG [dba57f80] Command: [ -w /var/www/html/ ]
DEBUG [dba57f80] Finished in 0.598 seconds with exit status 0 (successful).
INFO /var/www/html/ is writable on

Output (when I put everything in the staging file "capistrano/environments/staging.rb")

foo@bar:~$ cap staging check_write_permissions
DEBUG [dba57f80] Running /usr/bin/env [ -w /var/www/html/FooBarProject ] as
DEBUG [dba57f80] Command: [ -w /var/www/html/FooBarProject ]
DEBUG [dba57f80] Finished in 0.543 seconds with exit status 0 (successful).
INFO /var/www/html/ is writable on

I wonder if this happen because I changed the deploy_config_path... anyway, every variables I set in my deploy.rb file seems to be completely ignored...

Any ideas?

Copy link

@mattbrictson mattbrictson commented Oct 29, 2015

Yes, this is a bit tricky.

The problem is that :deploy_config_path must be an absolute path. Otherwise it will search in Ruby's default load path. So when you write this:

set :deploy_config_path, 'capistrano/deploy.rb'

You are actually instructing capistrano to load its own deploy.rb. In other words, it's as if you had written:

require "capistrano/deploy"

The solution is to pass an absolute path, which you can do in your Capfile like this:

set :deploy_config_path, File.expand_path('capistrano/deploy.rb')
Copy link
Contributor Author

@Oliboy50 Oliboy50 commented Oct 30, 2015

Great, it works just fine now. Thank you @mattbrictson

This should be in the doc :)

I keep this open until it's done. Feel free to close it :)

Copy link

@mattbrictson mattbrictson commented Oct 30, 2015

Could you open an issue for the missing documentation in the capistrano/documentation repository here?: (this is the repo for the site)

If you want to submit a PR to add the docs that would also help us a lot! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.