i am trying to deploy rails app through chef code. recipe contains code
deploy_revision "testapp" do
repo "REPO_URL"
ssh_wrapper "/home/ubuntu/.ssh/chef_ssh_deploy_wrapper.sh"
environment({
"RAILS_ENV" => "staging"
})
deploy_to "/home/ubuntu/testapp"
branch "master"
user "ubuntu"
group "ubuntu"
scm_provider Chef::Provider::Git
end
and sshwrapper file contains
exec ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no github.com -i "/home/ubuntu/.ssh/id_rsa" "$#"
when i ran bootstrap
im getting error as follows
STDERR: Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
192.168.1.32 Permission denied (publickey).
192.168.1.32 fatal: Could not read from remote repository.
192.168.1.32 Please make sure you have the correct access rights
192.168.1.32 and the repository exists.
192.168.1.32 ---- End output of git ls-remote "REPO_URL" master* ----
so , unable to figure it out the reason. Any help would be appreciated.
Related
I have a rubyonrails website which function in such a way that when a user signup with his username it create a repo in that username in my github account. It is working flawlessly in heroku. When I switched to amazon web service I initially get
intializing git
sh: git: command not found
sh: line 0: cd: /home/webapp: No such file or directory
I overcome this error by adding a config file in .ebextensions like
commands:
01_mkdir_webapp_dir:
# use the test directive to create the directory
# if the mkdir command fails the rest of this directive is ignored
test: 'mkdir /home/webapp'
command: 'ls -la /home/webapp'
02_chown_webapp_dir:
command: 'chown webapp:webapp /home/webapp'
03_chmod_webapp_dir:
command: 'chmod 700 /home/webapp'
packages:
yum:
git: []
Then I have a new error log like
fatal: could not read Username for 'https://github.com ': No such device or address
As a side note when I run this script locally, and I signed up the site at localhost:3000 terminal prompt me to submit github username and password. Is that normal. Is this is the cause of the error fatal: could not read Username for 'https://github.com ': No such device or address.
But this code works flawlessly in heroku.
Full log is below.
https://drive.google.com/file/d/1yPYsS1ETHhrEoYFWHJxt4y52jHYRkooj/view?usp=sharing
I have these environment set in aws.
https://photos.app.goo.gl/GeQHXdUWUMuixTgNA
Try to create git config file directly
#/home/webapp/.gitconfig
[user]
name = soumjoyel
email = soumjoyel#gmail.com
using this script
files:
"/home/webapp/.gitconfig" :
mode: "000644"
owner: webapp
group: webapp
content: |
[user]
name = soumjoyel
email = soumjoyel#gmail.com
I get the following when I try to deploy to server using capistrano gem from my local machine(MAC) {Rails app}. I am new to rails
user-mbp:xp user$ cap staging deploy
Server password:
********
DEBUG [c6110f69] Running /usr/bin/env [ -d ~/.rbenv ] as deployer#server.com
DEBUG [c6110f69] Command: [ -d ~/.rbenv ]
DEBUG [c6110f69] Finished in 6.956 seconds with exit status 0 (successful).
INFO [e385c416] Running /usr/bin/env mkdir -p /tmp/pepe/ as deployer#server.com
DEBUG [e385c416] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 /usr/bin/env mkdir -p /tmp/pepe/ )
INFO [e385c416] Finished in 0.098 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/pepe/git-ssh.sh 0.0%
INFO Uploading /tmp/pepe/git-ssh.sh 100.0%
INFO [191046c4] Running /usr/bin/env chmod +x /tmp/pepe/git-ssh.sh as deployer#server.com
DEBUG [191046c4] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 /usr/bin/env chmod +x /tmp/pepe/git-ssh.sh )`enter code here`
INFO [191046c4] Finished in 0.119 seconds with exit status 0 (successful).
INFO [bd99c2fc] Running /usr/bin/env git ls-remote --heads ssh://git#git.xxx.xx.com/xp.git as deployer#server.com
DEBUG [bd99c2fc] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/pepe/git-ssh.sh /usr/bin/env git ls-remote --heads ssh://git#git.xxx.xx.com/xp.git )
DEBUG [bd99c2fc] Permission denied (publickey,password).
DEBUG [bd99c2fc] fatal: The remote end hung up unexpectedly
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer#server.com: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly
SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly
I tried git:check, but still showing the same.
Tasks: TOP => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deployer#server.com: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly
Staging.rb
# *************************************************************** #
require 'highline'
set :stage, :staging
set :password, HighLine.new.ask('Server password:') { |q| q.echo = '*'}
server 'xx.x.com', user: 'deployer', password: fetch(:password), roles: %w{web app db}, primary: true
set :test_url, 'https://xx.x.com'
set :version, `git describe --always`
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
# and/or per server
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
# setting per server overrides global ssh_options
# fetch(:default_env).merge!(rails_env: :staging)
There are two possible solutions
Copy your private key to your deployment machine
As you can push to Github (this is what I understand) you have a private key on your development machine and the corresponding public key on Github. You can copy your private key onto your deployment machine to get rid of the error
develeopment-machine$ scp ~/.ssh/id-rsa.pub deployment-machine:key
Then ssh to your deployment machine and do
deployment-machine$ mv ~/.ssh/id-rsa.pub ~/.ssh/id-rsa.old
deployment-machine$ mv ~/key ~/.ssh/id-rsa.pub
Create a key on your deployment machine and add public key to Github
There is a easy to follow explanation how to do that at Github Help
Hope this helps.
Links to projects using Capistrano
If you are on Rails 3:
capfile
deploy.rb
environments
development notebook
If you are on Rails 4:
capfile
deploy.rb
environments
development notebook
I'm trying to deploy my Rails application with Capistrano but when it comes to "git ls-remote" i get the following error:
$ /usr/bin/env git ls-remote --heads git#git.<server>:<project>.git
/bin/bash: line 0: exec: corkscrew: not found
DEBUG [a5205e2a] ssh_exchange_identification: Connection closed by remote host
DEBUG [a5205e2a] fatal: The remote end hung up unexpectedly
If I try to run the command on the server there is no problem. I've also got a deploy ssh key for the "deployer" user in gitlab.
Corkscrew is located under ~/bin/corkscrew and is added to the PATH variable.
$ echo $PATH
/home/deployer/.rbenv/shims:/home/deployer/.rbenv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/deployer/bin
$ corkscrew
corkscrew 2.0 (agroman#agroman.net)
usage: corkscrew <proxyhost> <proxyport> <desthost> <destport> [authfile]
$ which corkscrew
~/bin/corkscrew
Update:
Here is my ~/.ssh/config:
Host *
ProxyCommand corkscrew <server> 8088 %h %p ~/.ssh/proxyauth
While the ~/.ssh/proxyauth file contains the credentials of the proxy user.
If you need additional information please let me know.
The problem seems to be that ssh can't find the corkscrew executable. I double-checked my local ~/.ssh/config file, and I use the full path to the corkscrew executable in there:
Host *
ProxyCommand /usr/local/bin/corkscrew <server> 8088 %h %p ~/.ssh/proxyauth
(Since I'm on OS X and have installed corkscrew through Homebrew, it's located in /usr/local/bin.)
Can you try to update your ~/.ssh/config to include the full path to the corkscrew executable? Something like this (I don't know whether the ~ will work, you might have to use the full path if it doesn't):
Host *
ProxyCommand ~/bin/corkscrew <server> 8088 %h %p ~/.ssh/proxyauth
While deploying a Rails app with Capistrano on Ubuntu 14.04, I am getting the following error:
fatal: destination path '/var/www/APP-NAME/repo' already exists and is not an empty directory.
cf5a389e] Running /usr/bin/env [ -f /var/www/rd/repo/HEAD ] on LINODE-INSTANCE-IP
DEBUG[cf5a389e] Command: [ -f /var/www/rd/repo/HEAD ]
DEBUG[cf5a389e] Finished in 0.005 seconds with exit status 1 (failed).
DEBUG[8899b95c] Running /usr/bin/env if test ! -d /var/www/rd; then echo "Directory does not exist '/var/www/rd'" 1>&2; false; fi on LINODE-INSTANCE-IP
DEBUG[8899b95c] Command: if test ! -d /var/www/rd; then echo "Directory does not exist '/var/www/rd'" 1>&2; false; fi
DEBUG[8899b95c] Finished in 0.005 seconds with exit status 0 (successful).
INFO[fc5f524b] Running /usr/bin/env git clone --mirror GIT_REPO_URL /var/www/APP-NAME/repo on LINODE-INSTANCE-IP
DEBUG[fc5f524b] Command: cd /var/www/APP-NAME && ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/rd/git-ssh.sh /usr/bin/env git clone --mirror GIT-REPO-URL /var/www/APP-NAME/repo )
DEBUG[fc5f524b] fatal: destination path '/var/www/APP-NAME/repo' already exists and is not an empty directory.
Here are config files:
config/deploy/production.rb
config/deploy.rb
The only reason for this error I can find online is;
same host in more than one role, so that they're racing? For example I mean that you might have the same IP address defined as an :app role host more than once.
Which I guess isn't fitting with the above config files.
I had the same problem. The reason is in double definition of the role and/or server.
Try to remove
server 'SERVER-IP', user: 'USERNAME', roles: %w{app}
in production.rb and
role :app, "SERVER-IP"
in deploy.rb. The latter seems to be just simple syntax while the former - is extended one, so you in fact you declare roles twice (three time to be more precise: 2 in production.rb and 1 in deploy.rb). Hope it helps.
On a related note, I ran into this issue when changing my DB connections file setup on one of my deploys.
In this case, the old structure had one shared file for DB settings, while the newer had two. Even though these were declared in the recipe, I was getting errors when automated deletion of older builds were being done.
To resolve, I just deleted the older builds, and ran the cap [server name] deploy a few times to clear it out, and to verify this was no longer occurring. So far, it's been fine.
I'm having loads of trouble getting my Chef recipe to clone a private repo. Well, I had it working yesterday but after 'cheffin' my Vagrant box half a dozen times, I've broken it. I'm a Chef newbie as you may guess.
Following the deploy_resource guide here, I've created my deploy.rb recipe (shortened):
deploy_branch "/var/www/html/ps" do
repo git#github.com:simonmorley/private-v2.git
ssh_wrapper "/tmp/.ssh/chef_ssh_deploy_wrapper.sh"
branch "rails4"
migrate false
environment "RAILS_ENV" => node[:ps][:rails_env]
purge_before_symlink %w{conf data log tmp public/system public/assets}
create_dirs_before_symlink []
symlinks( # the arrow is sort of reversed:
"conf" => "conf", # current/conf -> shared/conf
"data" => "data", # current/data -> shared/data
"log" => "log", # current/log -> shared/log
"tmp" => "tmp", # current/tmp -> shared/tmp
"system" => "public/system", # current/public/system -> shared/system
"assets" => "public/assets" # current/public/assets -> shared/assets
)
scm_provider Chef::Provider::Git # is the default, for svn: Chef::Provider::Subversion
notifies :restart, "service[ps]"
notifies :restart, "service[nginx]"
end
In defaults, I have the following to create the dirs etc.
directory "/tmp/.ssh" do
action :create
owner node[:base][:username]
group node[:base][:username]
recursive true
end
template "/tmp/.ssh/chef_ssh_deploy_wrapper.sh" do
source "chef_ssh_deploy_wrapper.sh.erb"
owner node[:base][:username]
mode 0770
end
# Put SSH private key to be used with SSH wrapper
template "/tmp/.ssh/id_deploy" do
source "id_rsa.pub.erb"
owner node[:base][:username]
mode 0600
end
And in the wrapper:
#!/bin/sh
exec ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "/tmp/.ssh/id_deploy" "$#"
And I have created a public key and uploaded this to github.
When I deploy the recipe, it gives me an error:
deploy_branch[/var/www/html/ps] action deployEnter passphrase for key '/tmp/.ssh/id_deploy':
Obvs I don't have a password set... The private key must therefore be missing..
Just by chance, I removed the id_deploy key from the recipe, deleted the folders and ran it again. Low and behold, it started working... The reason being that the id_rsa.pub && id_rsa files were in /root/.ssh from when I manually generated them to test.
I don't understand what I'm doing wrong here. My questions are therefore:
Do I need a private and public key on each node I deploy to? The docs don't mention this.
Should this not be deploying as non-root user? I have set a user in my roles file..
Why is the ssh_wrapper not doing what it's supposed to
It took a good couple of days to figure this out properly.
Just to clarify, this is what I did to fix it. I do not know if it's correct, but it works for me.
Generate a set of public and private keys following this tutorial.
Add the public key to the Github repo that you want to clone.
Create a template in my default recipe which includes both the public and private keys. See below.
Created the relevant templates for the pub and private keys.
Created the chef_ssh_deploy_wrapper.sh.erb file (see below)
Created a deploy.rb recipe (see below)
Uploaded and added the recipes to my role. Ran chef-client.
Hey presto! Sit back with a beer and watch your repo. smartly cloned into your dir.
The templates are as follows:
Create the directories and templates:
template "/tmp/.ssh/chef_ssh_deploy_wrapper.sh" do
source "chef_ssh_deploy_wrapper.sh.erb"
owner node[:base][:username]
mode 0770
end
template "/home/#{node[:base][:username]}/.ssh/id_rsa.pub" do
source "id_rsa.pub.erb"
owner node[:base][:username]
mode 0600
end
template "/home/#{node[:base][:username]}/.ssh/id_rsa" do
source "id_rsa.erb"
owner node[:base][:username]
mode 0600
end
Create an ssh wrapper chef_ssh_deploy_wrapper.erb
#!/bin/sh
exec ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "/home/#{node[:base][:username]}/.ssh/id_rsa" "$#"
(Make sure you use the private key here or it will fail)
Finally the deploy.rb recipe:
deploy_branch node[:my_app][:deploy_to] do
repo node[:base][:repository]
ssh_wrapper "/tmp/.ssh/chef_ssh_deploy_wrapper.sh"
branch "rails4"
user node[:base][:username]
group node[:base][:username]
rollback_on_error true
migrate false
environment "RAILS_ENV" => node[:my_app][:environment]
purge_before_symlink %w{conf data log tmp public/system public/assets}
create_dirs_before_symlink []
symlinks(
"config" => "config",
"data" => "data",
"log" => "log",
"tmp" => "tmp",
"system" => "public/system",
"assets" => "public/assets"
)
scm_provider Chef::Provider::Git # is the default, for svn: Chef::Provider::Subversion
before_restart do
system("su #{node[:base][:username]} -c 'cd #{node[:my_app][:deploy_to]}/current && /usr/bin/bundle install'") or raise "bundle install failed"
system("su #{node[:base][:username]} -c 'RAILS_ENV=production /usr/local/bin/rake assets:precompile'")
end
notifies :restart, "service[my_app]"
notifies :restart, "service[nginx]"
end
The before restart has since been replaced as we were initially compiling ruby from source but decided to use rvm in the end. Much easier for multi-user installations.
NB: I'm deploying as an sudo user, if you're doing so as root (avoid this), use the /root/.ssh path instead.
I took much inspiration from this article.
Good luck, I hope this helps someone.
Your question doesn't have a link to to the deploy_resource source, so I can't be sure if this will apply, but if it uses a git resource underneath, the following might be helpful...
As described in this answer to a similar question, you can avoid creating extra script files to go with each SSH key by adding the SSH command as an "external transport" part of the repository URL:
git "/path/to/destination" do
repository "ext::ssh -i /path/to/.ssh/deployment_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no git#github.com %S /my_name/some_repo.git"
branch "master"
...
end