chef-boneyard / chef-provisioning-aws

AWS driver and resources for Chef that uses the AWS SDK
Apache License 2.0
142 stars 121 forks source link

machine_batch exits with error - NoMethodError: undefined method `encoding' for nil:NilClass #277

Closed chocksaway closed 9 years ago

chocksaway commented 9 years ago

Chef provisioning - machine instance creation. SERVICES defined:

SERVICES = [
    {name: 'accounts', sg: SG1, type: 't2.micro', num: 1, eip: ACC_EIP},
    {name: 'authentication', sg: SG1, type: 't2.micro', num: 1, eip: AUTH_EIP},
    {name: 'resolution', sg: SG1, type: 't2.micro', num: 1, eip: RES_EIP},
    {name: 'onboarding', sg: SG1, type: 't2.micro', num: 1, eip: ON_EIP},
    {name: 'identity', sg: SG1, type: 't2.micro', num: 1, eip: ID_EIP},
    {name: 'index', sg: SG1, type: 't2.micro', num: 1, eip: INDEX_EIP},
    {name: 'transformation', sg: SG1, type: 't2.micro', num: 1, eip: TRAN_EIP},
    {name: 'repository', sg: SG1, type: 't2.micro', num: 1, eip: REPO_EIP},
    {name: 'query', sg: SG1, type: 't2.micro', num: 1, eip: QUERY_EIP},
    {name: 'couchdb', sg: SG2, type: 't2.micro', num: 1},
    {name: 'bigdata', sg: SG3, type: 'c3.large', num: 1},
    {name: 'dbindex', sg: SG3, type: 'c3.large', num: 1}

machine_batch creates instances:

services_length = SERVICES.length
services_half_way = (services_length / 2)   # whole number as integer division

machine_batch "one" do
  SERVICES[0..services_half_way].each do |srv|
    sleep(2) #reduce API calls per second in order to avoid limit

    srv[:num].times do |i|
      machine mc(srv[:name], i) do
        chef_server( :chef_server_url => 'http://localhost:8889')
        machine_options bootstrap_options: {
                            instance_type: srv[:type],
                            key_name: '***********',
                            subnet: SUB1,
                            security_group_ids: srv[:sg],
                            image_id: BASE_IMAGE
                        }
        retries 3
        retry_delay 5
        action :ready
      end
    end

    retries 3
    retry_delay 5
  end
end

Exits with a Stacktrace undefined method `encoding':

[2015-08-04T17:38:08+01:00] DEBUG: ---- HTTP Status and Header Data: ----
[2015-08-04T17:38:08+01:00] DEBUG: HTTP 1.1 200 OK
[2015-08-04T17:38:08+01:00] DEBUG: content-type: application/json
[2015-08-04T17:38:08+01:00] DEBUG: server: chef-zero
[2015-08-04T17:38:08+01:00] DEBUG: access-control-allow-origin: *
[2015-08-04T17:38:08+01:00] DEBUG: date: Tue, 04 Aug 2015 16:38:08 GMT
[2015-08-04T17:38:08+01:00] DEBUG: content-length: 2153
[2015-08-04T17:38:08+01:00] DEBUG: connection: close
[2015-08-04T17:38:08+01:00] DEBUG: ---- End HTTP Status/Header Data ----
[2015-08-04T17:38:08+01:00] DEBUG: Chef::HTTP calling Chef::HTTP::RemoteRequestID#handle_response
[2015-08-04T17:38:08+01:00] DEBUG: Chef::HTTP calling Chef::HTTP::Authenticator#handle_response
[2015-08-04T17:38:08+01:00] DEBUG: Chef::HTTP calling Chef::HTTP::Decompressor#handle_response
[2015-08-04T17:38:08+01:00] DEBUG: Chef::HTTP calling Chef::HTTP::CookieManager#handle_response
[2015-08-04T17:38:08+01:00] DEBUG: Chef::HTTP calling Chef::HTTP::JSONOutput#handle_response
[2015-08-04T17:38:08+01:00] DEBUG: Chef::HTTP calling Chef::HTTP::JSONInput#handle_response
[2015-08-04T17:38:08+01:00] DEBUG: Forwarding local server localhost:8889 to ubuntu@???.???.???.???
/etc/chef/client.rb
[2015-08-04T17:38:08+01:00] INFO: Completed ls -d /etc/chef/client.rb on ubuntu@???.???.???.???: exit status 0
[2015-08-04T17:38:08+01:00] INFO: Executing sudo md5sum -b /etc/chef/client.rb on ubuntu@???.???.???.???
[2015-08-04T17:38:08+01:00] INFO: Port forwarded: local URL http://localhost:8889 is available to ???.???.???.??? as http://localhost:8889 for the duration of this SSH connection.
[2015-08-04T17:38:08+01:00] INFO: Executing sudo ls -d /etc/chef/ohai/hints/ec2.json on ubuntu@???.???.???.???
9dcae696ddecdab5e476403dc9ef9932 */etc/chef/client.rb/etc/chef/ohai/hints/ec2.json

[2015-08-04T17:38:08+01:00] INFO: Completed ls -d /etc/chef/ohai/hints/ec2.json on ubuntu@???.???.???.???: exit status 0
[2015-08-04T17:38:08+01:00] INFO: Executing sudo md5sum -b /etc/chef/ohai/hints/ec2.json on ubuntu@???.???.???.???
[2015-08-04T17:38:08+01:00] INFO: Completed md5sum -b /etc/chef/client.rb on ubuntu@???.???.???.???: exit status 0
[2015-08-04T17:38:08+01:00] DEBUG: Closing SSH session on ubuntu@???.???.???.???
9d4568c009d203ab10e33ea9953a0264 */etc/chef/ohai/hints/ec2.json
[2015-08-04T17:38:08+01:00] INFO: Completed md5sum -b /etc/chef/ohai/hints/ec2.json on ubuntu@???.???.???.???: exit status 0
[2015-08-04T17:38:08+01:00] INFO: Executing sudo ls -d /etc/chef/client.rb on ubuntu@???.???.???.???
/etc/chef/client.rb
[2015-08-04T17:38:08+01:00] INFO: Completed ls -d /etc/chef/client.rb on ubuntu@???.???.???.???: exit status 0
[2015-08-04T17:38:08+01:00] INFO: Executing sudo md5sum -b /etc/chef/client.rb on ubuntu@???.???.???.???
c72d88372f335701e8f52df0db9cc274 */etc/chef/client.rb
[2015-08-04T17:38:08+01:00] INFO: Completed md5sum -b /etc/chef/client.rb on ubuntu@???.???.???.???: exit status 0
[2015-08-04T17:38:08+01:00] DEBUG: Closing SSH session on ubuntu@???.???.???.???
[2015-08-04T17:38:08+01:00] WARN: Resource.dsl_name is deprecated and will be removed in Chef 13.  Use resource_name instead.

    ================================================================================
    Error executing action `converge` on resource 'machine_batch[one]'
    ================================================================================

    NoMethodError
    -------------
    undefined method `encoding' for nil:NilClass

    Resource Declaration:
    ---------------------
    # In gitRepo/copyright-hub-provisioning/aws/vpc.rb

     85: machine_batch "one" do
     86:   SERVICES[0..services_half_way].each do |srv|
     87:     sleep(2) #reduce API calls per second in order to avoid limit
     88:
     89:     srv[:num].times do |i|
     90:       machine mc(srv[:name], i) do
     91:         chef_server( :chef_server_url => 'http://localhost:8889')
     92:         machine_options bootstrap_options: {
     93:                             instance_type: srv[:type],
     94:                             key_name: 'bamboo-key1',
     95:                             subnet: SUB1,
     96:                             security_group_ids: srv[:sg],
     97:                             image_id: BASE_IMAGE
     98:                         }
     99:         retries 3
    100:         retry_delay 5
    101:         action :ready
    102:       end
    103:     end
    104:
    105:     retries 3
    106:     retry_delay 5
    107:   end
    108: end
    109:

    Compiled Resource:
    ------------------
    # Declared in gitRepo/copyright-hub-provisioning/aws/vpc.rb:85:in `from_file'

    machine_batch("one") do
      action [:converge]
      retries 3
      retry_delay 5
      default_guard_interpreter :default
      driver "aws::eu-west-1"
      chef_server {:chef_server_url=>"chefzero://localhost:8889", :options=>{:client_name=>"CATMAC00082.local", :signing_key_filename=>nil}}
      declared_type :machine_batch
      cookbook_name "@recipe_files"
      recipe_name "gitRepo/copyright-hub-provisioning/aws/vpc.rb"
      machines ["davenport-accounts-0-chub-machine", "davenport-authentication-0-chub-machine", "davenport-resolution-0-chub-machine", "davenport-onboarding-0-chub-machine", "davenport-identity-0-chub-machine", "davenport-index-0-chub-machine", "davenport-transformation-0-chub-machine"]
    end

[2015-08-04T17:38:08+01:00] WARN: Resource.dsl_name is deprecated and will be removed in Chef 13.  Use resource_name instead.
[2015-08-04T17:38:08+01:00] INFO: Running queued delayed notifications before re-raising exception
[2015-08-04T17:38:08+01:00] DEBUG: Re-raising exception: NoMethodError - machine_batch[one] (@recipe_files::gitRepo/copyright-hub-provisioning/aws/vpc.rb line 85) had an error: NoMethodError: undefined method `encoding' for nil:NilClass
.rvm/rubies/ruby-head/lib/ruby/2.3.0/cgi/util.rb:8:in `escape'
  .rvm/gems/ruby-head/gems/mixlib-install-0.5.0/lib/mixlib/install.rb:107:in `install_command_vars_for_bourne'
  .rvm/gems/ruby-head/gems/mixlib-install-0.5.0/lib/mixlib/install.rb:94:in `install_command'
  .rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provisioning/convergence_strategy/install_sh.rb:42:in `setup_convergence'
  .rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provisioning/machine/basic_machine.rb:17:in `setup_convergence'
  .rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provider/machine_batch.rb:51:in `block (2 levels) in <class:MachineBatch>'
  .rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provider/machine_batch.rb:102:in `block (2 levels) in with_ready_machines'
  .rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provisioning/driver.rb:251:in `block in ready_machines'
  .rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb:267:in `call'
  .rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb:267:in `process_input'
  .rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb:257:in `process_one'
  .rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer.rb:93:in `call'
  .rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer.rb:93:in `worker_loop'

Running handlers:
[2015-08-04T17:38:08+01:00] ERROR: Running exception handlers
Running handlers complete
[2015-08-04T17:38:08+01:00] ERROR: Exception handlers complete
Chef Client failed. 6 resources updated in 191.894424 seconds
[2015-08-04T17:38:08+01:00] DEBUG: Server doesn't support resource history, skipping resource report.
[2015-08-04T17:38:08+01:00] DEBUG: Audit Reports are disabled. Skipping sending reports.
[2015-08-04T17:38:08+01:00] FATAL: Stacktrace dumped to .chef/local-mode-cache/cache/chef-stacktrace.out
[2015-08-04T17:38:08+01:00] DEBUG: NoMethodError: machine_batch[one] (@recipe_files::gitRepo/copyright-hub-provisioning/aws/vpc.rb line 85) had an error: NoMethodError: undefined method `encoding' for nil:NilClass
.rvm/rubies/ruby-head/lib/ruby/2.3.0/cgi/util.rb:8:in `escape'
.rvm/gems/ruby-head/gems/mixlib-install-0.5.0/lib/mixlib/install.rb:107:in `install_command_vars_for_bourne'
.rvm/gems/ruby-head/gems/mixlib-install-0.5.0/lib/mixlib/install.rb:94:in `install_command'
.rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provisioning/convergence_strategy/install_sh.rb:42:in `setup_convergence'
.rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provisioning/machine/basic_machine.rb:17:in `setup_convergence'
.rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provider/machine_batch.rb:51:in `block (2 levels) in <class:MachineBatch>'
.rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provider/machine_batch.rb:102:in `block (2 levels) in with_ready_machines'
.rvm/gems/ruby-head/bundler/gems/chef-provisioning-ea5dde23e427/lib/chef/provisioning/driver.rb:251:in `block in ready_machines'
.rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb:267:in `call'
.rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb:267:in `process_input'
.rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb:257:in `process_one'
.rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer.rb:93:in `call'
.rvm/gems/ruby-head/gems/chef-12.4.1/lib/chef/chef_fs/parallelizer.rb:93:in `worker_loop'
[2015-08-04T17:38:08+01:00] ERROR: machine_batch[one] (@recipe_files::gitRepo/copyright-hub-provisioning/aws/vpc.rb line 85) had an error: NoMethodError: undefined method `encoding' for nil:NilClass
[2015-08-04T17:38:08+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
CATMAC00082:copyright-hub-provisioning $
chocksaway commented 9 years ago

Here is my Gemfile.lock

GIT
  remote: https://github.com/chef/chef-provisioning-aws.git
  revision: 3635d8853f6169702c679cbd157a9dc46e2c8860
  specs:
    chef-provisioning-aws (1.4.0.dev.0)
      aws-sdk-v1 (>= 1.59.0)
      chef (>= 11.16.4)
      chef-provisioning (~> 1.0)
      retryable (~> 2.0.1)
      ubuntu_ami (~> 0.4.1)

GIT
  remote: https://github.com/chef/chef-provisioning.git
  revision: ea5dde23e4272f3082fdfdce6783fa7a6d883b70
  specs:
    chef-provisioning (1.3.0.dev.1)
      chef (>= 11.16.4)
      cheffish (~> 1.1)
      inifile (~> 2.0)
      mixlib-install (~> 0.4)
      net-scp (~> 1.0)
      net-ssh (~> 2.0)
      net-ssh-gateway (~> 1.2.0)
      winrm (~> 1.3)

GEM
  remote: https://rubygems.org/
  specs:
    addressable (2.3.8)
    aws-sdk-v1 (1.64.0)
      json (~> 1.4)
      nokogiri (>= 1.4.4)
    berkshelf (3.3.0)
      addressable (~> 2.3.4)
      berkshelf-api-client (~> 1.2)
      buff-config (~> 1.0)
      buff-extensions (~> 1.0)
      buff-shell_out (~> 0.1)
      celluloid (~> 0.16.0)
      celluloid-io (~> 0.16.1)
      cleanroom (~> 1.0)
      faraday (~> 0.9.0)
      httpclient (~> 2.6.0)
      minitar (~> 0.5.4)
      octokit (~> 3.0)
      retryable (~> 2.0)
      ridley (~> 4.0)
      solve (~> 1.1)
      thor (~> 0.19)
    berkshelf-api-client (1.3.0)
      faraday (~> 0.9.0)
      httpclient (~> 2.6.0)
    buff-config (1.0.1)
      buff-extensions (~> 1.0)
      varia_model (~> 0.4)
    buff-extensions (1.0.0)
    buff-ignore (1.1.1)
    buff-ruby_engine (0.1.0)
    buff-shell_out (0.2.0)
      buff-ruby_engine (~> 0.1.0)
    builder (3.2.2)
    celluloid (0.16.0)
      timers (~> 4.0.0)
    celluloid-io (0.16.2)
      celluloid (>= 0.16.0)
      nio4r (>= 1.1.0)
    chef (12.4.1)
      chef-config (= 12.4.1)
      chef-zero (~> 4.2, >= 4.2.2)
      diff-lcs (~> 1.2, >= 1.2.4)
      erubis (~> 2.7)
      ffi-yajl (~> 2.2)
      highline (~> 1.6, >= 1.6.9)
      mixlib-authentication (~> 1.3)
      mixlib-cli (~> 1.4)
      mixlib-log (~> 1.3)
      mixlib-shellout (>= 2.0.0.rc.0, < 3.0)
      net-ssh (~> 2.6)
      net-ssh-multi (~> 1.1)
      ohai (~> 8.0)
      plist (~> 3.1.0)
      pry (~> 0.9)
      rspec-core (~> 3.2)
      rspec-expectations (~> 3.2)
      rspec-mocks (~> 3.2)
      rspec_junit_formatter (~> 0.2.0)
      serverspec (~> 2.7)
      specinfra (~> 2.10)
      syslog-logger (~> 1.6)
    chef-config (12.4.1)
      mixlib-config (~> 2.0)
      mixlib-shellout (~> 2.0)
    chef-zero (4.2.3)
      ffi-yajl (>= 1.1, < 3.0)
      hashie (~> 2.0)
      mixlib-log (~> 1.3)
      rack
      uuidtools (~> 2.1)
    cheffish (1.3.0)
      chef (~> 12.1)
      chef-zero (~> 4.2)
    cleanroom (1.0.0)
    coderay (1.1.0)
    dep-selector-libgecode (1.0.2)
    dep_selector (1.0.3)
      dep-selector-libgecode (~> 1.0)
      ffi (~> 1.9)
    diff-lcs (1.2.5)
    erubis (2.7.0)
    faraday (0.9.1)
      multipart-post (>= 1.2, < 3)
    ffi (1.9.10)
    ffi-yajl (2.2.2)
      libyajl2 (~> 1.2)
    git (1.2.9.1)
    gssapi (1.2.0)
      ffi (>= 1.0.1)
    gyoku (1.3.1)
      builder (>= 2.1.2)
    hashie (2.1.2)
    highline (1.7.3)
    hitimes (1.2.2)
    httpclient (2.6.0.1)
    inifile (2.0.2)
    ipaddress (0.8.0)
    json (1.8.3)
    libyajl2 (1.2.0)
    little-plugger (1.1.3)
    logging (1.8.2)
      little-plugger (>= 1.1.3)
      multi_json (>= 1.8.4)
    method_source (0.8.2)
    mime-types (2.6.1)
    mini_portile (0.6.2)
    minitar (0.5.4)
    mixlib-authentication (1.3.0)
      mixlib-log
    mixlib-cli (1.5.0)
    mixlib-config (2.2.1)
    mixlib-install (0.5.0)
    mixlib-log (1.6.0)
    mixlib-shellout (2.1.0)
    multi_json (1.11.2)
    multipart-post (2.0.0)
    net-http-persistent (2.9.4)
    net-scp (1.2.1)
      net-ssh (>= 2.6.5)
    net-ssh (2.10.0)
    net-ssh-gateway (1.2.0)
      net-ssh (>= 2.6.5)
    net-ssh-multi (1.2.1)
      net-ssh (>= 2.6.5)
      net-ssh-gateway (>= 1.2.0)
    net-telnet (0.1.1)
    nio4r (1.1.1)
    nokogiri (1.6.6.2)
      mini_portile (~> 0.6.0)
    nori (2.6.0)
    octokit (3.8.0)
      sawyer (~> 0.6.0, >= 0.5.3)
    ohai (8.5.0)
      ffi (~> 1.9)
      ffi-yajl (~> 2.2)
      ipaddress
      mime-types (~> 2.0)
      mixlib-cli
      mixlib-config (~> 2.0)
      mixlib-log
      mixlib-shellout (~> 2.0)
      rake (~> 10.1)
      systemu (~> 2.6.4)
      wmi-lite (~> 1.0)
    plist (3.1.0)
    pry (0.10.1)
      coderay (~> 1.1.0)
      method_source (~> 0.8.1)
      slop (~> 3.4)
    rack (1.6.4)
    rake (10.4.2)
    retryable (2.0.1)
    ridley (4.2.0)
      addressable
      buff-config (~> 1.0)
      buff-extensions (~> 1.0)
      buff-ignore (~> 1.1)
      buff-shell_out (~> 0.1)
      celluloid (~> 0.16.0)
      celluloid-io (~> 0.16.1)
      erubis
      faraday (~> 0.9.0)
      hashie (>= 2.0.2, < 3.0.0)
      json (>= 1.7.7)
      mixlib-authentication (>= 1.3.0)
      net-http-persistent (>= 2.8)
      retryable (~> 2.0)
      semverse (~> 1.1)
      varia_model (~> 0.4)
    rspec (3.3.0)
      rspec-core (~> 3.3.0)
      rspec-expectations (~> 3.3.0)
      rspec-mocks (~> 3.3.0)
    rspec-core (3.3.2)
      rspec-support (~> 3.3.0)
    rspec-expectations (3.3.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-its (1.2.0)
      rspec-core (>= 3.0.0)
      rspec-expectations (>= 3.0.0)
    rspec-mocks (3.3.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-support (3.3.0)
    rspec_junit_formatter (0.2.3)
      builder (< 4)
      rspec-core (>= 2, < 4, != 2.12.0)
    rubyntlm (0.4.0)
    sawyer (0.6.0)
      addressable (~> 2.3.5)
      faraday (~> 0.8, < 0.10)
    semverse (1.2.1)
    serverspec (2.20.0)
      multi_json
      rspec (~> 3.0)
      rspec-its
      specinfra (~> 2.38)
    sfl (2.2)
    slop (3.6.0)
    solve (1.2.1)
      dep_selector (~> 1.0)
      semverse (~> 1.1)
    specinfra (2.40.0)
      net-scp
      net-ssh (~> 2.7)
      net-telnet
      sfl
    syslog-logger (1.6.8)
    systemu (2.6.5)
    thor (0.19.1)
    timers (4.0.1)
      hitimes
    ubuntu_ami (0.4.1)
    uuidtools (2.1.5)
    varia_model (0.4.0)
      buff-extensions (~> 1.0)
      hashie (>= 2.0.2, < 3.0.0)
    winrm (1.3.3)
      builder (>= 2.1.2)
      gssapi (~> 1.2)
      gyoku (~> 1.0)
      httpclient (~> 2.2, >= 2.2.0.2)
      logging (~> 1.6, >= 1.6.1)
      nori (~> 2.0)
      rubyntlm (~> 0.4.0)
      uuidtools (~> 2.1.2)
    wmi-lite (1.0.0)

PLATFORMS
  ruby

DEPENDENCIES
  berkshelf
  chef-provisioning!
  chef-provisioning-aws!
  git

BUNDLED WITH
   1.10.6
chocksaway commented 9 years ago

Closed accidently (doh).

tyler-ball commented 9 years ago

@thommay We're seeing this in provisioning using 0.5.0 of mixlib-install. chef_version is nil in provisioning. Could we default it in mixlib-install to latest?

https://github.com/chef/mixlib-install/blob/v0.5.0/lib/mixlib/install.rb#L68