title: Running a Capistrano deployment task with AWS user-data
body: <p>My scenario : I have an AMI with a <code>deploy/</code> folder that contains the capistrano files that I use to deploy a production application on localhost</p>
  
  <p>I was planning to use a user-data script from an Autoscaling group, to deploy the most recent version of the server each time the group scales up and spawns a new machine</p>
  
  <p>The script must be ran as the user ubuntu</p>
  
  <p>Here is my user-data</p>
  
  <pre><code>cd /home/ubuntu/
  aws s3 cp s3://mybucket-config/production/rails/startup_script.sh ./startup_script.sh --region my-region
  chmod +x ./startup_script.sh
  chown ubuntu:ubuntu ./startup_script.sh
  su - ubuntu -c "./startup_script.sh"
  </code></pre>
  
  <p>This startup script contains</p>
  
  <pre><code>cd /home/ubuntu/deploy/
  git pull
  git checkout production
  cap aws_localhost_production deploy
  </code></pre>
  
  <p>I run into a weird error message during the <code>cap deploy</code>, and I didn't find a lot of references on google about this one</p>
  
  <blockquote>
    <p>NoMethodError: undefined method `winsize' for nil:NilClass</p>
  </blockquote>
  
  <p>Here is the full stack</p>
  
  <pre><code>The deploy has failed with an error: undefined method `winsize' for nil:NilClass
  /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/console.rb:61:in `console_width': undefined method `winsize' for nil:NilClass (NoMethodError)
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/console.rb:26:in `print_line'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/capistrano/tasks.rb:77:in `each_line'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/capistrano/tasks.rb:77:in `error_line'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/capistrano/tasks.rb:42:in `deploy_failed'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/capistrano.rb:15:in `block (2 levels) in &lt;top (required)&gt;'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:248:in `block in execute'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:243:in `each'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:243:in `execute'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/airbrussh-1.0.1/lib/airbrussh/rake/context.rb:55:in `execute'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
          from /usr/share/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/task.rb:173:in `invoke'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/lib/capistrano/dsl.rb:15:in `invoke'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/lib/capistrano/dsl/task_enhancements.rb:56:in `exit_deploy_because_of_exception'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/lib/capistrano/application.rb:73:in `exit_because_of_exception'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/application.rb:186:in `rescue in standard_exception_handling'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/lib/capistrano/application.rb:14:in `run'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/capistrano-3.5.0/bin/cap:3:in `&lt;top (required)&gt;'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/bin/cap:23:in `load'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/bin/cap:23:in `&lt;main&gt;'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
          from /home/ubuntu/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `&lt;main&gt;'
  </code></pre>