Chef makes Redmine installation failing

I try to install Redmine via APT and Chef but it does not work.

I always get the error

Could not find gem 'rails (~> 4.2.7)' in any of the gem sources listed in your
Gemfile.

It seems to be Chef related because the same apt command works when execute it by myself.

Here is the output of Chef:

[2019-02-27T17:47:35-05:00] WARN: *****************************************
[2019-02-27T17:47:35-05:00] WARN: Did not find config file: /root/.chef/chef.rb, using command line options.
[2019-02-27T17:47:35-05:00] WARN: *****************************************
[2019-02-27T17:47:35-05:00] WARN: No cookbooks directory found at or above current directory.  Assuming /root.
[2019-02-27T17:47:35-05:00] FATAL: Cannot load configuration from nodes/redmine.json
root@debian:~# cd chef-repo/
root@debian:~/chef-repo# chef-client -z -j nodes/redmine.json -c .chef/chef.rb
Starting Chef Client, version 14.10.9
resolving cookbooks for run list: ["my-redmine"]
Synchronizing Cookbooks:
  - my-redmine (1.0.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: my-redmine::default
  * apt_package[redmine] action install

    ================================================================================
    Error executing action `install` on resource 'apt_package[redmine]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '100'
    ---- Begin output of ["apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "redmine=3.3.1-4+deb9u2"] ----
    STDOUT: Reading package lists...
    Building dependency tree...
    Reading state information...
    The following additional packages will be installed:
      dbconfig-common dbconfig-sqlite3 fontconfig-config fonts-dejavu-core
      fonts-droid-fallback fonts-lato fonts-noto-mono ghostscript gsfonts
      imagemagick-6-common javascript-common libavahi-client3 libavahi-common-data
      libavahi-common3 libcups2 libcupsfilters1 libcupsimage2 libcurl3
      libfftw3-double3 libfontconfig1 libgomp1 libgs9 libgs9-common libijs-0.35
      libjbig0 libjbig2dec0 libjpeg62-turbo libjs-coffeescript libjs-jquery
      libjs-source-map libjs-uglify liblcms2-2 liblqr-1-0 libltdl7
      libmagickcore-6.q16-3 libmagickwand-6.q16-3 libopenjp2-7 libpaper-utils
      libpaper1 libruby2.3 libtiff5 libuv1 libxslt1.1 libyaml-0-2 nodejs passenger
      poppler-data rake redmine-sqlite ruby ruby-actionmailer ruby-actionpack
      ruby-actionpack-action-caching ruby-actionpack-xml-parser ruby-actionview
      ruby-activejob ruby-activemodel ruby-activerecord ruby-activesupport
      ruby-addressable ruby-arel ruby-atomic ruby-binding-of-caller
      ruby-blankslate ruby-builder ruby-bundler ruby-byebug ruby-coderay
      ruby-coffee-rails ruby-coffee-script ruby-coffee-script-source
      ruby-columnize ruby-concurrent ruby-css-parser ruby-debug-inspector
      ruby-did-you-mean ruby-erubis ruby-execjs ruby-ffi ruby-globalid ruby-hike
      ruby-hmac ruby-htmlentities ruby-i18n ruby-jbuilder ruby-jquery-rails
      ruby-json ruby-listen ruby-loofah ruby-mail ruby-mime-types ruby-mimemagic
      ruby-minitest ruby-molinillo ruby-multi-json ruby-net-http-persistent
      ruby-net-ldap ruby-net-telnet ruby-nokogiri ruby-oj ruby-openid
      ruby-pkg-config ruby-polyglot ruby-power-assert ruby-protected-attributes
      ruby-rack ruby-rack-openid ruby-rack-test ruby-rails
      ruby-rails-deprecated-sanitizer ruby-rails-dom-testing
      ruby-rails-html-sanitizer ruby-rails-observers ruby-railties ruby-rb-inotify
      ruby-rbpdf ruby-rbpdf-font ruby-redcarpet ruby-request-store ruby-rmagick
      ruby-roadie ruby-roadie-rails ruby-sass ruby-sass-rails ruby-sdoc
      ruby-spring ruby-sprockets ruby-sprockets-rails ruby-sqlite3 ruby-test-unit
      ruby-thor ruby-thread-safe ruby-tilt ruby-treetop ruby-turbolinks
      ruby-tzinfo ruby-uglifier ruby-web-console ruby2.3 rubygems-integration
      sqlite3 unzip zip
    Suggested packages:
      fonts-noto ghostscript-x apache2 | lighttpd | httpd cups-common libfftw3-bin
      libfftw3-dev coffeescript liblcms2-utils libmagickcore-6.q16-3-extra
      passenger-doc rails poppler-utils fonts-japanese-mincho
      | fonts-ipafont-mincho fonts-japanese-gothic | fonts-ipafont-gothic
      fonts-arphic-ukai fonts-arphic-uming fonts-nanum bzr cvs darcs mercurial
      ruby-fcgi subversion ri ruby-dev ruby-builder-doc doc-base treetop bundler
      sqlite3-doc
    The following NEW packages will be installed:
      dbconfig-common dbconfig-sqlite3 fontconfig-config fonts-dejavu-core
      fonts-droid-fallback fonts-lato fonts-noto-mono ghostscript gsfonts
      imagemagick-6-common javascript-common libavahi-client3 libavahi-common-data
      libavahi-common3 libcups2 libcupsfilters1 libcupsimage2 libcurl3
      libfftw3-double3 libfontconfig1 libgomp1 libgs9 libgs9-common libijs-0.35
      libjbig0 libjbig2dec0 libjpeg62-turbo libjs-coffeescript libjs-jquery
      libjs-source-map libjs-uglify liblcms2-2 liblqr-1-0 libltdl7
      libmagickcore-6.q16-3 libmagickwand-6.q16-3 libopenjp2-7 libpaper-utils
      libpaper1 libruby2.3 libtiff5 libuv1 libxslt1.1 libyaml-0-2 nodejs passenger
      poppler-data rake redmine redmine-sqlite ruby ruby-actionmailer
      ruby-actionpack ruby-actionpack-action-caching ruby-actionpack-xml-parser
      ruby-actionview ruby-activejob ruby-activemodel ruby-activerecord
      ruby-activesupport ruby-addressable ruby-arel ruby-atomic
      ruby-binding-of-caller ruby-blankslate ruby-builder ruby-bundler ruby-byebug
      ruby-coderay ruby-coffee-rails ruby-coffee-script ruby-coffee-script-source
      ruby-columnize ruby-concurrent ruby-css-parser ruby-debug-inspector
      ruby-did-you-mean ruby-erubis ruby-execjs ruby-ffi ruby-globalid ruby-hike
      ruby-hmac ruby-htmlentities ruby-i18n ruby-jbuilder ruby-jquery-rails
      ruby-json ruby-listen ruby-loofah ruby-mail ruby-mime-types ruby-mimemagic
      ruby-minitest ruby-molinillo ruby-multi-json ruby-net-http-persistent
      ruby-net-ldap ruby-net-telnet ruby-nokogiri ruby-oj ruby-openid
      ruby-pkg-config ruby-polyglot ruby-power-assert ruby-protected-attributes
      ruby-rack ruby-rack-openid ruby-rack-test ruby-rails
      ruby-rails-deprecated-sanitizer ruby-rails-dom-testing
      ruby-rails-html-sanitizer ruby-rails-observers ruby-railties ruby-rb-inotify
      ruby-rbpdf ruby-rbpdf-font ruby-redcarpet ruby-request-store ruby-rmagick
      ruby-roadie ruby-roadie-rails ruby-sass ruby-sass-rails ruby-sdoc
      ruby-spring ruby-sprockets ruby-sprockets-rails ruby-sqlite3 ruby-test-unit
      ruby-thor ruby-thread-safe ruby-tilt ruby-treetop ruby-turbolinks
      ruby-tzinfo ruby-uglifier ruby-web-console ruby2.3 rubygems-integration
      sqlite3 unzip zip
    0 upgraded, 144 newly installed, 0 to remove and 0 not upgraded.
    Need to get 48.9 MB of archives.
    After this operation, 170 MB of additional disk space will be used.
    Get:1 http://security.debian.org/debian-security stretch/updates/main amd64 libruby2.3 amd64 2.3.3-1+deb9u4 [3110 kB]
    Get:2 http://ftp.us.debian.org/debian stretch/main amd64 fonts-droid-fallback all 1:6.0.1r16-1.1 [1807 kB]
    Get:3 http://security.debian.org/debian-security stretch/updates/main amd64 ruby2.3 amd64 2.3.3-1+deb9u4 [188 kB]
    Get:4 http://ftp.us.debian.org/debian stretch/main amd64 fonts-lato all 2.0-1 [2684 kB]
    Get:5 http://ftp.us.debian.org/debian stretch/main amd64 liblqr-1-0 amd64 0.4.2-2+b2 [24.8 kB]
    Get:6 http://ftp.us.debian.org/debian stretch/main amd64 libgomp1 amd64 6.3.0-18+deb9u1 [73.3 kB]
    Get:7 http://ftp.us.debian.org/debian stretch/main amd64 libfftw3-double3 amd64 3.3.5-3 [731 kB]
    ...
    ...
    ...
    Get:144 http://ftp.us.debian.org/debian stretch/main amd64 zip amd64 3.0-11+b1 [234 kB]
    Preconfiguring packages ...
    Fetched 48.9 MB in 32s (1505 kB/s)
    Selecting previously unselected package fonts-droid-fallback.
(Reading database ... 41787 files and directories currently installed.)
    Preparing to unpack .../000-fonts-droid-fallback_1%3a6.0.1r16-1.1_all.deb ...
    Unpacking fonts-droid-fallback (1:6.0.1r16-1.1) ...
    Selecting previously unselected package fonts-lato.
    Preparing to unpack .../001-fonts-lato_2.0-1_all.deb ...
    Unpacking fonts-lato (2.0-1) ...
    Selecting previously unselected package liblqr-1-0:amd64.
    Preparing to unpack .../002-liblqr-1-0_0.4.2-2+b2_amd64.deb ...
    Unpacking liblqr-1-0:amd64 (0.4.2-2+b2) ...
    Selecting previously unselected package libgomp1:amd64.
    Preparing to unpack .../003-libgomp1_6.3.0-18+deb9u1_amd64.deb ...
    Unpacking libgomp1:amd64 (6.3.0-18+deb9u1) ...
    Selecting previously unselected package libfftw3-double3:amd64.
    Preparing to unpack .../004-libfftw3-double3_3.3.5-3_amd64.deb ...
    Unpacking libfftw3-double3:amd64 (3.3.5-3) ...
    Selecting previously unselected package fonts-dejavu-core.
    Preparing to unpack .../005-fonts-dejavu-core_2.37-1_all.deb ...
    Unpacking fonts-dejavu-core (2.37-1) ...
    Selecting previously unselected package fontconfig-config.
    Preparing to unpack .../006-fontconfig-config_2.11.0-6.7_all.deb ...
    Unpacking fontconfig-config (2.11.0-6.7) ...
    Selecting previously unselected package libfontconfig1:amd64.
    Preparing to unpack .../007-libfontconfig1_2.11.0-6.7+b1_amd64.deb ...
    Unpacking libfontconfig1:amd64 (2.11.0-6.7+b1) ...
    Selecting previously unselected package libjbig0:amd64.
    Preparing to unpack .../008-libjbig0_2.1-3.1+b2_amd64.deb ...
    Unpacking libjbig0:amd64 (2.1-3.1+b2) ...
    Selecting previously unselected package libjpeg62-turbo:amd64.
    Preparing to unpack .../009-libjpeg62-turbo_1%3a1.5.1-2_amd64.deb ...
    Unpacking libjpeg62-turbo:amd64 (1:1.5.1-2) ...
    Selecting previously unselected package liblcms2-2:amd64.
    Preparing to unpack .../010-liblcms2-2_2.8-4+deb9u1_amd64.deb ...
    Unpacking liblcms2-2:amd64 (2.8-4+deb9u1) ...
    Selecting previously unselected package libltdl7:amd64.
    Preparing to unpack .../011-libltdl7_2.4.6-2_amd64.deb ...
    Unpacking libltdl7:amd64 (2.4.6-2) ...
    Selecting previously unselected package libopenjp2-7:amd64.
    Preparing to unpack .../012-libopenjp2-7_2.1.2-1.1+deb9u2_amd64.deb ...
    Unpacking libopenjp2-7:amd64 (2.1.2-1.1+deb9u2) ...
    Selecting previously unselected package libtiff5:amd64.
    Preparing to unpack .../013-libtiff5_4.0.8-2+deb9u4_amd64.deb ...
    Unpacking libtiff5:amd64 (4.0.8-2+deb9u4) ...
    Selecting previously unselected package imagemagick-6-common.
    Preparing to unpack .../014-imagemagick-6-common_8%3a6.9.7.4+dfsg-11+deb9u6_all.deb ...
    Unpacking imagemagick-6-common (8:6.9.7.4+dfsg-11+deb9u6) ...
    Selecting previously unselected package libmagickcore-6.q16-3:amd64.
    Preparing to unpack .../015-libmagickcore-6.q16-3_8%3a6.9.7.4+dfsg-11+deb9u6_amd64.deb ...
    Unpacking libmagickcore-6.q16-3:amd64 (8:6.9.7.4+dfsg-11+deb9u6) ...
    Selecting previously unselected package libmagickwand-6.q16-3:amd64.
    Preparing to unpack .../016-libmagickwand-6.q16-3_8%3a6.9.7.4+dfsg-11+deb9u6_amd64.deb ...
    Unpacking libmagickwand-6.q16-3:amd64 (8:6.9.7.4+dfsg-11+deb9u6) ...
    Selecting previously unselected package poppler-data.
    Preparing to unpack .../017-poppler-data_0.4.7-8_all.deb ...
    Unpacking poppler-data (0.4.7-8) ...
    Selecting previously unselected package dbconfig-common.
    Preparing to unpack .../018-dbconfig-common_2.0.8_all.deb ...
    Unpacking dbconfig-common (2.0.8) ...
    Selecting previously unselected package sqlite3.
    Preparing to unpack .../019-sqlite3_3.16.2-5+deb9u1_amd64.deb ...
    Unpacking sqlite3 (3.16.2-5+deb9u1) ...
    Selecting previously unselected package dbconfig-sqlite3.
    Preparing to unpack .../020-dbconfig-sqlite3_2.0.8_all.deb ...
    Unpacking dbconfig-sqlite3 (2.0.8) ...
    ...
    ...        
    ...
    Setting up ruby-builder (3.2.2-4) ...
    Setting up ruby-activemodel (2:4.2.7.1-1) ...
    Setting up ruby-jbuilder (2.3.1-1) ...
    Setting up ruby-sprockets (3.7.0-1+deb9u1) ...
    Setting up ruby-bundler (1.13.6-2) ...
    Setting up ruby-rails-html-sanitizer (1.0.3-2) ...
    Setting up ruby-activerecord (2:4.2.7.1-1) ...
    Setting up ruby-rails-dom-testing (1.0.6-1) ...
    Setting up ruby-activejob (2:4.2.7.1-1) ...
    Setting up ruby-rack-openid (1.4.2-1) ...
    Setting up ruby-protected-attributes (1.1.3-2) ...
    Setting up ruby-rails-observers (0.1.2-1) ...
    Setting up ruby-actionview (2:4.2.7.1-1) ...
    Setting up ruby-actionpack (2:4.2.7.1-1) ...
    Setting up ruby-actionpack-xml-parser (1.0.2-2) ...
    Setting up ruby-actionmailer (2:4.2.7.1-1) ...
    Setting up ruby-railties (2:4.2.7.1-1) ...
    Setting up ruby-sprockets-rails (2.3.2-1) ...
    Setting up ruby-roadie-rails (1.1.0-1) ...
    Setting up ruby-actionpack-action-caching (1.1.1-4) ...
    Setting up ruby-jquery-rails (4.2.1-2) ...
    Setting up ruby-coffee-rails (4.1.0-2) ...
    Setting up ruby-rails (2:4.2.7.1-1) ...
    Setting up redmine (3.3.1-4+deb9u2) ...
    Could not find gem 'rails (~> 4.2.7)' in any of the gem sources listed in your
    Gemfile.
    dpkg: error processing package redmine (--configure):
     subprocess installed post-installation script returned error exit status 1
    Setting up ruby-sass-rails (5.0.6-1) ...
    Setting up ruby-web-console (2.2.1-2) ...
    Setting up ruby-turbolinks (2.5.3-3) ...
    Processing triggers for libc-bin (2.24-11+deb9u4) ...
    Errors were encountered while processing:
     redmine
Extracting templates from packages: 100%ckages: 20%
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    ---- End output of ["apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "redmine=3.3.1-4+deb9u2"] ----
    Ran ["apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "redmine=3.3.1-4+deb9u2"] returned 100

    Resource Declaration:
    ---------------------
    # In /root/chef-repo/.chef/local-mode-cache/cache/cookbooks/my-redmine/recipes/default.rb

     20: package 'redmine' do
     21:   action :install
     22: end

    Compiled Resource:
    ------------------
    # Declared in /root/chef-repo/.chef/local-mode-cache/cache/cookbooks/my-redmine/recipes/default.rb:20:in `from_file'

    apt_package("redmine") do
      package_name "redmine" 
      action [:install]
      default_guard_interpreter :default
      declared_type :package
      cookbook_name "my-redmine" 
      recipe_name "default" 
    end

    System Info:
    ------------
    chef_version=14.10.9
    platform=debian
    platform_version=9.8
    ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
    program_name=/usr/bin/chef-client
    executable=/opt/chef/bin/chef-client

Running handlers:
[2019-02-27T17:48:38-05:00] ERROR: Running exception handlers
Running handlers complete
[2019-02-27T17:48:38-05:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 59 seconds
[2019-02-27T17:48:38-05:00] FATAL: Stacktrace dumped to /root/chef-repo/.chef/local-mode-cache/cache/chef-stacktrace.out
[2019-02-27T17:48:38-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-02-27T17:48:38-05:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: apt_package[redmine] (my-redmine::default line 20) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '100'
---- Begin output of ["apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "redmine=3.3.1-4+deb9u2"] ----