2

I am trying to install the package 'ntp' on a vagrant instance using chef.

This is my chef recipe:

package 'ntp' do
        action :install
end

I have also tried using this as my recipe:

package 'ntp'

What is wrong with these scripts? Also what would be best practices for something like this?

Sorry id this is something really simple that I am not getting. I have tried googling it a lot to find out how but I cant find anything. I have also tried looking at the chef docs but am not able to figure it out.

This is the error output that I keep getting:

-----> Starting Kitchen (v1.19.2)
-----> Converging <default-ubuntu-1604>...
       Preparing files for transfer
       Preparing dna.json
       Resolving cookbook dependencies with Berkshelf 6.3.1...
       Removing non-cookbook files before transfer
       Preparing validation.pem
       Preparing client.rb
-----> Chef Omnibus installation detected (install only if missing)
       Transferring files to <default-ubuntu-1604>
       Starting Chef Client, version 13.7.16
       resolving cookbooks for run list: ["git_cookbook::default"]
       Synchronizing Cookbooks:
         - git_cookbook (0.1.0)
       Installing Cookbook Gems:
       Compiling Cookbooks...
       Converging 1 resources
       Recipe: git_cookbook::default
         * apt_package[ntp] action install

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

           Mixlib::ShellOut::ShellCommandFailed
           ------------------------------------
           Expected process to exit with [0], but received '100'
           ---- Begin output of ["apt-get", "-q", "-y", "install", "ntp=1:4.2.8p4+dfsg-3ubuntu5.7"] ----
           STDOUT: Reading package lists...
           Building dependency tree...
           Reading state information...
           The following additional packages will be installed:
             libopts25
           Suggested packages:
             ntp-doc
           The following NEW packages will be installed:
             libopts25 ntp
           0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
           Need to get 518 kB/576 kB of archives.
           After this operation, 1792 kB of additional disk space will be used.
           Err:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 ntp amd64 1:4.2.8p4+dfsg-3ubuntu5.7
             404  Not Found [IP: 91.189.88.162 80]
           STDERR: E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/n/ntp/ntp_4.2.8p4+dfsg-3ubuntu5.7_amd64.deb  404  Not Found [IP: 91.189.88.162 80]

           E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
           ---- End output of ["apt-get", "-q", "-y", "install", "ntp=1:4.2.8p4+dfsg-3ubuntu5.7"] ----
           Ran ["apt-get", "-q", "-y", "install", "ntp=1:4.2.8p4+dfsg-3ubuntu5.7"] returned 100

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/git_cookbook/recipes/default.rb

             1: package 'ntp' do
             2:         action :install
             3: end

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/git_cookbook/recipes/default.rb:1:in `from_file'

           apt_package("ntp") do
             package_name "ntp"
             action [:install]
             default_guard_interpreter :default
             declared_type :package
             cookbook_name "git_cookbook"
             recipe_name "default"
           end

           System Info:
           ------------
           chef_version=13.7.16
           platform=ubuntu
           platform_version=16.04
           ruby=ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]
           program_name=chef-client worker: ppid=5272;start=06:22:55;
           executable=/opt/chef/bin/chef-client


       Running handlers:
       [2018-02-26T06:23:02+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2018-02-26T06:23:02+00:00] ERROR: Exception handlers complete
       Chef Client failed. 0 resources updated in 07 seconds
       [2018-02-26T06:23:02+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2018-02-26T06:23:02+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-02-26T06:23:02+00:00] ERROR: apt_package[ntp] (git_cookbook::default line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '100'
       ---- Begin output of ["apt-get", "-q", "-y", "install", "ntp=1:4.2.8p4+dfsg-3ubuntu5.7"] ----
       STDOUT: Reading package lists...
       Building dependency tree...
       Reading state information...
       The following additional packages will be installed:
         libopts25
       Suggested packages:
         ntp-doc
       The following NEW packages will be installed:
         libopts25 ntp
       0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
       Need to get 518 kB/576 kB of archives.
       After this operation, 1792 kB of additional disk space will be used.
       Err:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 ntp amd64 1:4.2.8p4+dfsg-3ubuntu5.7
         404  Not Found [IP: 91.189.88.162 80]
       STDERR: E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/n/ntp/ntp_4.2.8p4+dfsg-3ubuntu5.7_amd64.deb  404  Not Found [IP: 91.189.88.162 80]

       E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
       ---- End output of ["apt-get", "-q", "-y", "install", "ntp=1:4.2.8p4+dfsg-3ubuntu5.7"] ----
       Ran ["apt-get", "-q", "-y", "install", "ntp=1:4.2.8p4+dfsg-3ubuntu5.7"] returned 100
       [2018-02-26T06:23:03+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Converge failed on instance <default-ubuntu-1604>.  Please see .kitchen/logs/default-ubuntu-1604.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration
izzzi
  • 35
  • 5

1 Answers1

1

Your instance has not updated package indexes for a while / or just have outdated package indexes. From my experience, it is a good practice to put include_recipe "apt" at the top of the first recipe in your chef run, it will run apt-get update, before any other resource (You can do it yourself, but it has some caveats. Using provided recipe is simpler).

Apt cookbook is available on the supermarket.

Szymon
  • 1,525
  • 1
  • 11
  • 12
  • Do I need to have the apt cookbook with my ntp cookboot or should just adding `include_recipe "ntp"` work? – izzzi Feb 26 '18 at 22:08
  • If you want to use apt cookbook, you have to add it to metadata.rb of your cookbook and you have to distribute them together (for example with Berkshelf). Sorry, but I do not get second part, with including `ntp`, where do you want to add `include_recipe "ntp"`? – Szymon Feb 27 '18 at 05:59
  • Sorry I meant to say the include "apt" part. I added that to my recipe but I didn't do anything and I can only assume it was because that was the only change I made and I didn't actually add the cookbook – izzzi Feb 27 '18 at 07:39
  • Default [apt recipe](https://github.com/chef-cookbooks/apt/blob/master/recipes/default.rb) should run apt-get update for you. – Szymon Feb 27 '18 at 13:06