5

I wonder if there is a simple way to get all the currently set variables in Capistrano 3?

So if I have:

set :user, "deploy"
set :application, "someapp"

I would like to get something like:

all_variables # => { user: "deploy", application: "someapp", ... }

Thanks

Dmitry Sokurenko
  • 6,042
  • 4
  • 32
  • 53

3 Answers3

4

I was looking for the same thing and found Capistrano::Configuration.env.

namespace :dump do
  task :env do
    pp Capistrano::Configuration.env
  end
end

This should allow you to view all :set variables by calling cap dump:env.

Use fetch to get the values.

Fetch mention in getting started guide

Quick Edit: To get exactly what you're looking for try:

all_variables = Capistrano::Configuration.env.instance_eval{ @config }
1

This works well

vars = Capistrano::Configuration
  .env
  .instance_eval { @variables }
  .trusted_keys
Dino Reic
  • 3,586
  • 3
  • 22
  • 11
0

For Capistrano 2, we can use variables module - ref - https://github.com/capistrano/capistrano/blob/v2.15.5/lib/capistrano/configuration/variables.rb

namespace :dump do
  task :variables do
    p variables.inspect
  end
end
Parvez Kazi
  • 660
  • 5
  • 13