Skip to content

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

@Oliboy50

Description

@Oliboy50

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)

Capfile

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 }

capistrano/deploy.rb

lock '3.4.0'

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

set :scm, :git
set :repo_url, 'git@github.com:Something/FooBarProject.git'

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

capistrano/environments/staging.rb

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 'my-own-domain.com',
  roles: %w{web app db},
  user: fetch(:ssh_user),
  ssh_options: {
    auth_methods: %w(publickey),
    keys: %w(staging/id_rsa)
  }

capistrano/tasks/check.cap

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}"
    else
      error "#{fetch(:deploy_to)} is not writable on #{host}"
    end
  end
end

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 oliboy25@my-own-domain.com
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 my-own-domain.com

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 oliboy25@my-own-domain.com
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 my-own-domain.com

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions