sous-chefs / jenkins

Development repository for the jenkins cookbook
https://supermarket.chef.io/cookbooks/jenkins
Apache License 2.0
424 stars 635 forks source link

Docker Installation in Jenkins Fail: Error executing action `add` on resource 'apt_repository[docker]' #744

Closed hassanhashmy closed 3 years ago

hassanhashmy commented 4 years ago

I am trying to install docker in Jenkins using chef, my environment is legacy so using old versions. My Jenkins server went down due to some problem and now it is not coming up due to problem in docker installation.

System Information

OS: Ubuntu 14.04.5 LTS Chef Version: 12.8.1 Jenkins Cookbook: Version: 2.5.0

I am calling Jenkins cookbook in my cookbook hassan_jenkins and in hassan_jenkins, I do have this docker recipe.

This is my docker installation recipe

include_recipe 'sysctl::default'
sysctl_param 'net.ipv4.ip_forward' do
  value 1
end

apt_repository 'docker' do
  uri = "https://download.docker.com/linux/#{node['platform']}"
  distribution = node['lsb']['codename']
  components ['main']
  keyserver = 'keyserver.ubuntu.com'
  key = '9DC858229FC7DD38854AE2D88D81803C0EBFCD88'
  action :add
end

package %w(linux-image-extra-virtual docker-ce) do
  action :install
  options "-o Dpkg::Options::='--force-confnew'"
end

docker_opts_localhost_regex = %r{DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock"}
docker_opts_localhost = 'DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock"'
ruby_block 'set docker to bind to localhost' do
  block do
    fe = Chef::Util::FileEdit.new('/etc/default/docker')
    fe.insert_line_if_no_match(docker_opts_localhost_regex, docker_opts_localhost)
    fe.write_file
  end
  not_if do
    ::File.readlines('/etc/default/docker').grep(docker_opts_localhost_regex).any?
  end
  notifies :restart, 'service[docker]', :delayed
end

service 'docker' do
  provider Chef::Provider::Service::Upstart
  action [:enable, :start]
  supports :status => true, :start => true, :stop => true, :restart => true, :reload => true
end

And this is the error

apt_repository[docker] action add[2020-06-02T01:45:19+00:00] INFO: Processing apt_repository[docker] action add (hassan_jenkins::_docker line 15)

    ================================================================================
    Error executing action `add` on resource 'apt_repository[docker]'
    ================================================================================

    NoMethodError
    -------------
    undefined method `start_with?' for nil:NilClass

    Cookbook Trace:
    ---------------
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb:234:in `is_ppa_url?'
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb:77:in `block in <class:AptRepository>'
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `instance_eval'
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:132:in `compile_and_converge_action'
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action'
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels) in converge'
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each'
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge'
    /var/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'

    Resource Declaration:
    ---------------------
    # In /var/chef/cookbooks/hassan_jenkins/recipes/_docker.rb

     15: apt_repository 'docker' do
     16:   uri = "https://download.docker.com/linux/#{node['platform']}"
     17:   distribution = node['lsb']['codename']
     18:   components ['main']
     19:   keyserver = 'keyserver.ubuntu.com'
     20:   key = '9DC858229FC7DD38854AE2D88D81803C0EBFCD88'
     21:   action :add
     22: end
     23:

    Compiled Resource:
    ------------------
    # Declared in /var/chef/cookbooks/hassan_jenkins/recipes/_docker.rb:15:in `from_file'

    apt_repository("docker") do
      action [:add]
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      declared_type :apt_repository
      cookbook_name :hassan_jenkins
      recipe_name "_docker"
      components ["main"]
    end
hassanhashmy commented 4 years ago

Some Info added

github-actions[bot] commented 3 years ago

Marking stale due to inactivity. Remove stale label or comment or this will be closed in 7 days. Alternatively drop by the #sous-chefs channel on the Chef Community Slack and we'll be happy to help! Thanks, Sous-Chefs.

github-actions[bot] commented 3 years ago

Closing due to inactivity. If this is still an issue please reopen or open another issue. Alternatively drop by the #sous-chefs channel on the Chef Community Slack and we'll be happy to help! Thanks, Sous-Chefs.