forward3d / cap-ec2

Capify-EC2 rewritten for Capistrano v3
MIT License
181 stars 118 forks source link

empty list when I run util tasks #51

Closed satboy78 closed 9 years ago

satboy78 commented 9 years ago

Hi, I'm having some troubles using cap-ec2, I always get an empty list when I run util tasks.

In capistrano v2 deploy tool, I used to connect to my production machines using set :gateway, "deploy@xxxxxxxx" set :ssh_options, { :forward_agent => true } default_run_options[:pty] = true ssh_options[:port] = "22" ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa_deploy_xxxxx")]

Can you please help me figuring out how to fix it?

This is the command I run: cap app:app1-live ec2:status

Thanks a lot.

Best regards, Matteo

Here you can see my configuration (I have a multi-stage / multi-application deploy tool).


GEMFILE source "https://rubygems.org" gem "capistrano", ">=3.0.0" gem "capistrano-multiconfig", ">=3.0.3" gem 'capistrano-symfony', '~> 0.1' gem 'capistrano-composer' gem 'capistrano-file-permissions' gem 'cap-ec2'


CAPFILE require 'capistrano/multiconfig' require 'capistrano/deploy' require "cap-ec2/capistrano" require 'capistrano/symfony' require 'capistrano/file-permissions' require 'capistrano/composer'


GEMFILE.LOCK GEM remote: https://rubygems.org/ specs: aws-sdk-v1 (1.64.0) json (~> 1.4) nokogiri (>= 1.4.4) cap-ec2 (1.0.0) aws-sdk-v1 capistrano (>= 3.0) colorize terminal-table capistrano (3.4.0) i18n rake (>= 10.0.0) sshkit (~> 1.3) capistrano-bower (1.1.0) capistrano (~> 3.0) capistrano-composer (0.0.6) capistrano (>= 3.0.0.pre) capistrano-file-permissions (0.1.1) capistrano (~> 3.1) capistrano-grunt (0.0.4) capistrano (>= 3.0.0.pre) capistrano-log_with_awesome (0.0.2) capistrano (>= 2.5.14) capistrano-multiconfig (3.0.8) capistrano (>= 3.0.0) capistrano-npm (1.0.1) capistrano (>= 3.0.0) capistrano-symfony (0.4.0) capistrano (~> 3.1) capistrano-composer (~> 0.0.3) capistrano-file-permissions (~> 0.1.0) colorize (0.7.7) i18n (0.7.0) json (1.8.2) mini_portile (0.6.2) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (2.9.2) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) rake (10.4.2) sshkit (1.7.1) colorize (>= 0.7.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) terminal-table (1.4.5)


EC2.YML access_key_id: "xxxxxxxxxxxxxxx" secret_access_key: "xxxxxxxxxxx" regions:


DEPLOY.RB ('config' folder) set :scm, :git set :format, :pretty set :log_level, :debug set :pty, true set :default_env, { path: "/opt/ruby/bin:$PATH" } set :keep_releases, 5


APP.RB ('config/deploy' folder) ... set :application, 'SETA' ...


APP1-LIVE.RB ('config/deploy/app' folder) ... configuration_file = "config/deploy/app/parameters/app1-live.yml" require "cap-ec2/capistrano" set :ec2_config, "config/ec2.yml"

ec2_role :web, user: 'deploy', roles: %w{app web}, primary: true, ssh_options: { user: 'deploy', keys: %w(keys/id_rsa_deploy_mtvsouth), auth_methods: %w(publickey) }

ec2_role :app, user: 'deploy', roles: %w{app web}, primary: true, ssh_options: { user: 'deploy', keys: %w(keys/id_rsa_deploy_mtvsouth), auth_methods: %w(publickey) }

satboy78 commented 9 years ago

Hi, I've created another file named production.rb in deploy folder. (so it's not a multi-application deploy tool)

I used the same settings I've sent you before, and now I can see a server in the list.

The command I used is cap production ec2:status

Do you think that cap-ec2 doesn't work with multi-stage / multi-application deploy scripts?

Hope this can help to figure out how to solve my issue.

Thanks a lot.

Best regards. Matteo


PRODUCTION.RB

set :user, "deploy" set :scm, :git set :repo_url, "ssh://git@stash.XXXX.com/intl-XXXX/XXXX.git"

set :application, 'XXXX'

require "cap-ec2/capistrano" set :ec2_config, "config/ec2.yml"

ec2_role :web, user: 'deploy', ssh_options: { user: 'deploy', keys: %w(keys/id_rsa_deploy_XXXXX), auth_methods: %w(publickey) }

ec2_role :app, user: 'deploy', ssh_options: { user: 'deploy', keys: %w(keys/id_rsa_deploy_XXXXX), auth_methods: %w(publickey) }

andytinycat commented 9 years ago

This question is asked a lot, and the answer is: unless the tags on your instance(s) precisely line up with the tags you specified in Cap-EC2, it's not going to work. My advice to you is to double check all your tag names and tag values.

I don't see you setting a :stage in your stage files. Capistrano v3 won't automatically define a stage based on the name of a file or its path - you must explicitly set a stage.

Additionally, this command doesn't make sense:

cap app:app1-live ec2:status

The syntax for Capistrano is cap [stage] [task]; have you called your stage app:app1-live?

satboy78 commented 9 years ago

Hi @andytinycat, thanks a lot for your answer; as I told you, my script is a multi-application and multi-stage deployment tool, so I used CapHub

As you can see, with CapHub we have this repository layout

[mysite-deploy]$ tree --dirsfirst . ├── config │ ├── deploy │ │ ├── billing │ │ │ ├── production.rb │ │ │ └── qa.rb │ │ ├── core │ │ │ ├── production.rb │ │ │ └── qa.rb │ │ └── customer │ │ ├── production.rb │ │ └── qa.rb │ ├── keys │ └── deploy.rb ├── recipes ├── Capfile └── Gemfile

so we have commands like this

cap customer:production deploy

I've double checked my settings, and in fact I created another script with the same settings of my first script (the only difference is that this new script isn't multi-application), and in that case I get a list of ec2 instances.

Do you think I can use cap-ec2 with caphub?

Thanks a lot.

Best regards, Matteo

satboy78 commented 9 years ago

Hi, I've made another test; I've created a 'production' folder and an empty 'production-live.rb' file inside it (so I've simulated a multi-application / multi-stage caphub script).

Here you can see the results (production.rb is the same file in both tests)

screenshot from 2015-05-25 11 41 13

production (no caphub) works, production:production-live (using caphub) doesn't work.

I think that cap-ec2 doesn't work with multi-application / multi-stage caphub scripts; do you think it's possible to make it working even with these scripts?

Thanks a lot.

Best regards, Matteo

andytinycat commented 9 years ago

CapHub does nothing special as far as I can see; it's a very simple template generator.

As I said before, you need to check the tags on your instances.

Your tags look wrong, from that screenshot. If you want an instance to be part of a stage, you must make sure the instance has a tag "Stages", and contains the name of the stage.

So in your example, your instance must have a Stages tag containing production:production-live.

satboy78 commented 9 years ago

thanks a lot, now it works!

this is another difference with capistrano 2, I used 'production-live' as stage tag, now I have to use 'production:production-live'