1

It is possible to install software using Ansible and Puppet by downloading a role from galaxy or puppetforge and run it masterless.

Aim

The aim is to install MongoDB using chef masterless. I just want to download a cookbook and run it.

Attempt

  • knife cookbook site download mongodb3 saved the cookbook in /home/user/mongodb3-5.3.0.tar.gz
  • The tar was extracted
  • Based on this documentation I tried to run the cookbook using chef-client --local -o recipe['mongodb3'], but it resulted in:

[2016-11-18T10:35:28+01:00] WARN: No config file found or specified on command line, using command line options.
[2016-11-18T10:35:28+01:00] WARN: No cookbooks directory found at or above current directory.  Assuming /home/user.
Starting Chef Client, version 12.15.19
[2016-11-18T10:36:05+01:00] WARN: Run List override has been provided.
[2016-11-18T10:36:05+01:00] WARN: Original Run List: []
[2016-11-18T10:36:05+01:00] WARN: Overridden Run List: [recipe[mongodb3]]
resolving cookbooks for run list: ["mongodb3"]

================================================================================
Error Resolving Cookbooks for Run List:
================================================================================

Missing Cookbooks:
------------------
No such cookbook: mongodb3

Expanded Run List:
------------------
* mongodb3

Platform:
---------
x86_64-linux


Running handlers:
[2016-11-18T10:36:05+01:00] ERROR: Running exception handlers
Running handlers complete
[2016-11-18T10:36:05+01:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 36 seconds
[2016-11-18T10:36:05+01:00] FATAL: Stacktrace dumped to /home/user/.chef/local-mode-cache/cache/chef-stacktrace.out
[2016-11-18T10:36:05+01:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-11-18T10:36:05+01:00] ERROR: 412 "Precondition Failed"
[2016-11-18T10:36:05+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Attempt 2

It is possible to run Chef code using the example as provided by @TimHaintz:

[2016-11-28T08:19:12+01:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.15.19
[2016-11-28T08:19:15+01:00] WARN: Run List override has been provided.
[2016-11-28T08:19:15+01:00] WARN: Original Run List: []
[2016-11-28T08:19:15+01:00] WARN: Overridden Run List: [recipe[helloworld]]
resolving cookbooks for run list: ["helloworld"]
Synchronizing Cookbooks:
  - helloworld (0.0.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: helloworld::default
  * file[/home/user/x.txt] action create
    - create new file /home/user/x.txt
    - update content in file /home/user/x.txt from none to 787ec7
    --- /home/user/x.txt    2016-11-28 08:19:15.527057085 +0100
    +++ /home/user/.chef-x20161128-7678-no5ia3.txt  2016-11-28 08:19:15.527057085 +0100
    @@ -1 +1,2 @@
    +HELLO WORLD
    - restore selinux security context
[2016-11-28T08:19:15+01:00] WARN: Skipping final node save because override_runlist was given

Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 03 seconds

Questions

  1. When to use knife, chef-apply, chef-client, chef-shell or chef-solo?
  2. What is the shortest way to run a cookbook from the marketplace?
5
  • Do you have a chef server and a client? Or are you using your local machine? If you are using your local machine, you can download ChefDK. You then use test kitchen to test cookbooks etc. If you have a server and client setup, you need to bootstrap your client with the chef client software. Once you do that you assign that cookbook to the client and chef will 'make it so'. knife node run_list add is the section you are looking for.
    – Tim Haintz
    Commented Nov 18, 2016 at 10:04
  • Within your cookbook, you will have a metadata.rb file. You need a depends section in there. For example: depends 'windows_ad'. Then in your recipe, you need to reference that cookbook. So in my recipe, to reference windows_ad, I have: include_recipe 'windows_ad::default'
    – Tim Haintz
    Commented Nov 18, 2016 at 10:12
  • 1
    have you looked into ChefDK? That is the local installer which everything runs locally on your computer. I currently use it with Virtual Box and Vagrant. Spins up virtuals etc. downloads.chef.io/chef-dk. That will let you test out cookbooks etc. without using any infrastructure other than you local machine.
    – Tim Haintz
    Commented Nov 18, 2016 at 10:14
  • Sorry @030 I haven't used Puppet or Ansible.
    – Tim Haintz
    Commented Nov 18, 2016 at 10:15
  • 1
    Hopefully this blog helps @030. I have never done what you are asking. blog.chef.io/2013/10/31/… looks like you can though. Hope this helps.
    – Tim Haintz
    Commented Nov 18, 2016 at 10:19

2 Answers 2

2

knife cookbook site download just gives you a raw tarball, not in a format you can use with Chef directly. If you're looking for a fully-feature chef-solo workflow I would use the knife-solo plugin together with Berkshelf.

Put the cookbooks you want to use in the Berksfile and then use knife solo cook to transfer them to the target node and run chef-solo.

3
  • knife solo does not exist
    – 030
    Commented Nov 28, 2016 at 11:14
  • It's a plugin matschaffer.github.io/knife-solo
    – coderanger
    Commented Nov 28, 2016 at 16:13
  • +1 for advising to use berkshelf to manage cookbooks from the supermarket.
    – 030
    Commented Nov 28, 2016 at 16:35
1

@coderanger advised to use berkshelf and the following snippets were found in this documentation:

Berksfile

source "https://supermarket.chef.io"

cookbook "terraform"

Installing the cookbooks

user@host ~ $ berks install
Resolving cookbook dependencies...
Fetching cookbook index from https://supermarket.chef.io...
Installing ark (1.1.0)
Installing compat_resource (12.16.2)
Installing seven_zip (2.0.2)
Installing build-essential (7.0.2)
Installing ohai (4.2.2)
Using terraform (0.5.3)
Installing mingw (1.2.4)
Installing windows (2.1.1)

run berks vendor

user@host ~ $ berks vendor
Resolving cookbook dependencies...
Using terraform (0.5.3)
Using ark (1.1.0)
Using mingw (1.2.4)
Using ohai (4.2.2)
Using build-essential (7.0.2)
Using seven_zip (2.0.2)
Using compat_resource (12.16.2)
Using windows (2.1.1)
Vendoring ark (1.1.0) to /home/user/berks-cookbooks/ark
Vendoring build-essential (7.0.2) to /home/user/berks-cookbooks/build-essential
Vendoring compat_resource (12.16.2) to /home/user/berks-cookbooks/compat_resource
Vendoring mingw (1.2.4) to /home/user/berks-cookbooks/mingw
Vendoring ohai (4.2.2) to /home/user/berks-cookbooks/ohai
Vendoring seven_zip (2.0.2) to /home/user/berks-cookbooks/seven_zip
Vendoring terraform (0.5.3) to /home/user/berks-cookbooks/terraform
Vendoring windows (2.1.1) to /home/user/berks-cookbooks/windows

the following snippets are based on this answer:

config.rb

cookbook_path [
  '/home/user/berks-cookbooks'
]

config.json

{
  "run_list": [
    "terraform"
  ]
}

Run

sudo chef-solo -c config.rb -j config.json

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .