I have a question about using the Rubber gem to deploy a Rails app to EC2. When I go about running
cap rubber:create_staging
This line of code runs in a loop.
executing `rubber:_allow_root_ssh'
executing "sudo -p 'sudo password: ' bash -l -c 'cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/'"
servers: ["witheld"]
. Failed to connect to witheld, retrying
I believe this may be an issue with my keypairs.
In terms of my keynames, I have a current private key called keyname (plain text file) and a public key called keyname.pub in my config/rubber folder. My rubber.yml file lists
key_name: keyname
key_file: "#{Dir[(File.expand_path('~') rescue '/root') + '/.ec2/*' + cloud_providers.aws.key_name].first}"
I'm pretty sure all other information is correct, but I obviously can't copy and paste it in. Any suggestions?
your keys should be in ~/.ec2/ folder not in config/rubber folder. also make sure you remove .pem extension from your private key file and .pub stays with your public file.
Also change key_name: [your private key file name here] in your rubber.yml file.
based on your key_file: settings, rubber will look for these keys in ~/.ec2 folder. So move them to there.
Related
I had changed my personal token on github because this expired and after this it did not work when I executed in console "Bundle install" and this showed this error:
dev) bundle install
Authentication is required for https://Andre***#rubygems.pkg.github.com/Cuseum/.
Please supply credentials for this source. You can do this by running:
bundle config https://Andrea****#rubygems.pkg.github.com/Cus**/ username:password
Authentication is required for https://Andre***#rubygems.pkg.github.com/Cuseum/.
Please supply credentials for this source. You can do this by running:
bundle config https://Andrea****#rubygems.pkg.github.com/Cus**/ username:password
my solution was the following:
in this file
~ cd .bundle/confing
with cat I look at the file's content and use vim to replace the old password with the new one:
➜ .bundle cat config
---
BUNDLE_GITHUB__HTTPS: "true"
BUNDLE_GEMS__CONTRIBSYS__COM: "0163a338:7bfd2049"
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/CUS****/: "AndreaRoMa:ghp_jafHFM8NFbiAWPJE9Do2***************"
BUNDLE_HTTPS://ANDR****#RUBYGEMS__PKG__GITHUB__COM/CUSEUM/: "Andre****:******"
➜ .bundle vim config
➜ .bundle cat config
---
BUNDLE_GITHUB__HTTPS: "true"
BUNDLE_GEMS__CONTRIBSYS__COM: "0163a338:7bfd2049"
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/CUs***/: "Andrea****:ghp_YBEZ8AkqbowPHxhrlumSouyQwItCK******"
BUNDLE_HTTPS://ANDRE***#RUBYGEMS__PKG__GITHUB__COM/CUSEUM/: "Andre****:*****"
I changed some letters for ** but in these fields, only put your data.
I've added new HDD to the server and need to use it to save all users info, so I need to move public directory to new HDD.
I don't know what is the best approach in my case, but I decided to change the public directory to be symbolic link pointing to new HDD path.
Based on that I created the below capistrano task to run after deploy:
# I'm using capistrano 3.1
namespace :public_to_symbolic do
desc 'Change public directory to symbolic link pointing to other Hdd'
task :change do
on roles(:app) do
is_directory = File.directory?("#{release_path}/public")
is_symbolic_link = File.symlink?("#{release_path}/public")
is_new_directory_exist = File.directory?('/mnt/newhdd/public')
can_change = is_directory && !is_symbolic_link && is_new_directory_exist
puts "is_directory : #{is_directory}" # prints false
puts "is_symbolic_link : #{is_symbolic_link}" # prints false
puts "is_new_directory_exist : #{is_new_directory_exist}" # prints false
puts "can_change: #{can_change}" # prints false
puts "release_path: #{release_path}" # prints /var/www/myapp/releases/20180305112922
if can_change
puts 'Changing public directory to symbolic link'
execute "mv #{release_path}/public #{release_path}/public_linked"
execute "ln -s /mnt/newhdd/public #{release_path}/public"
execute "rm -rf #{release_path}/public_linked"
end
end
end
end
after 'deploy', 'public_to_symbolic:change'
So, as commented, is_directory, is_symbolic_link and is_new_directory_exist are all returns false, but when I'm doing the same check (i.e File.directory?("#{Rails.root}/public") or File.directory?("/var/www/myapp/current/public")) using Rails console on deployment server, I'm getting true and I'm able to see the public directory!
To avoid this issue I tried also to use current_path instead of release_path but still same results.
I have two questions:
Why is_directory and is_new_directory_exist are always false while task is running?
If there is any better approach to use public directory on different Hdd, please advice.
All suggestions are welcome
All Ruby methods that you use in your Capistrano tasks run on your local machine.
For example:
File.directory?
File.symlink?
These are always evaluated on your local filesystem. Capistrano never runs Ruby code on the remote server. These methods always return false for you because they are trying to find e.g. "#{release_path}/public" on your local computer, which of course does not exist.
To run code on the server, the tools available to you are Capistrano's test and execute methods. These take in a command string that is executed remotely via SSH.
If you want to test if a remote path is a directory, you cannot use Ruby; you have to use something that can be run in a remote shell. Here is one way to test if a path is a directory, for example:
is_directory = test("[ -d #{release_path}/public ]")
Likewise, to test if a path is a symlink:
is_symbolic_link = test("[ -h #{release_path}/public ]")
I'm trying to perform a "knife bootstrap" command through Jenkins web UI execute shell, but I keep getting this error message :
(this is the knife bootstrap command I'm using) :
"knife bootstrap [the node's IP] --ssh-user ec2-user --sudo --identity-file "[my key to the node]" --node-name My123 --run-list 'role[role1]' "
and this is the error message:
" ERROR: Errno::ENOENT: No such file or directory # rb_sysopen - /etc/chef/validation.pem "
when I run the 'knife bootstrap' command directly through the CLI it works fine.
any idea why it's not working from Jenkins execute shell?
It is due to validation.pem file is missing, this is default path for validation file. Either you can set path in /chef-repo/.chef/knife.rb file or you can use default location /etc/chef/validation.pem.
You can regenerate validation key from webUI and replace the existing one, this should resolve your issue.
I am trying to create an EC2 using knife and knife-ec2 gem
command example :
knife ec2 server create --image ami-f7f03d80 -i --flavor t2.micro -x root -i /root/europe.pem —sud —groups chef-client -Z eu-west-1a -r “role[xmpp]”
Error output :
ERROR: Excon::Errors::SocketError: getaddrinfo: Name or service not known (SocketError)
knife.rb :
log_level :info
log_location STDOUT
node_name 'ec2-user'
client_key '/root/.chef/ec2-user.pem'
validation_client_name 'chef-validator'
validation_key '/etc/chef-server/chef-validator.pem'
chef_server_url 'https://ip-****.eu-west-1.compute.internal:443'
syntax_check_cache_path '/root/.chef/syntax_check_cache'
knife[:aws_access_key_id] = '*****'
knife[:aws_secret_access_key] = '*****'
knife[:region] = 'eu-west-1a'
--
gem list knife-ec2
*** LOCAL GEMS ***
knife-ec2 (0.8.0)
Can any one put me on the right direction, i a m suspecting an issue with the ruby gems.
PS :
for some reason knife ec2 flavor list works fine.
Thanks in advance.
regards,
Amine
>
SOLUTION :
fixed by : - reinstalling the ruby gems - reusing the patched version of ec2 create .rb
That error means it's not able to resolve the hostname I believe. I'd start there.
I have the COMODO Extended Validation offered by NameCheap.com. It gives me these files:
[domain]_com.crt
AddTrustExternalCARoot.crt
COMODOAddTrustServerCA.crt
COMODOExtendedValidationSecureServerCA.crt
I did everything I was supposed to in regards to unpacking site.key and what not, but what I did not do was combine the 4 items listed above in to one file. I merely did
$ heroku certs:add [domain]_com.crt site.key --app myapp
After doing some research and cat'ing them all in to one file
$ cat [domain]_com.crt COMODOExtendedValidationSecureServerCA.crt /
COMODOAddTrustServerCA.crt AddTrustExternalCARoot.crt > [domain]_com-bundle.pem
I am trying to do
$ heroku certs:update [new_file].pem site.key --app myapp
But I get these errors:
Resolving trust chain... done
Updating SSL Endpoint [app].herokussl.com for [myapp]... failed
! Pem can't be blank
! Pem is invalid
! Expires at can't be blank
Did I do the PEM file wrong? Did I cat them in the wrong order?
I think I figured it out and made a blog post about it here:
http://starvingdeveloper.wordpress.com/2012/09/18/comodo-ev-ssl-with-heroku-if-you-did-it-wrong-the-first-time/