How run cookbook with dependencies in chef?

后端 未结 3 1899
遥遥无期
遥遥无期 2021-01-23 17:57

I have configured workstation up this step in get started (OS redhat 6.5). I have launched a node. I modified a cookbook like that:

myCookbook/metadata.rb

相关标签:
3条回答
  • 2021-01-23 18:34

    @rastasheep has described how the berkshelf tool is now bundled with the chefdk package.

    It's really easy to use and worth learning. It's designed to work like the gem bundler tool.

    Example

    └── myCookbook
        ├── Berksfile       <-- Berkshelf configuration file
        ├── Berksfile.lock  <-- Lock file generated by Berkshelf
        ├── metadata.rb
        ├── README.md
        └── recipes
            └── default.rb
    

    Berksfile

    source "https://supermarket.getchef.com"
    
    metadata
    

    The "source" directive tells berkshelf where to download dependencies from. The "metadata" directive tells berkshelf to take dependencies from the cookbook metadata.

    Using Berkshelf

    The "install" command will download the cookbook dependencies (Cached under ~/.berkshelf)

    $ cd myCookbook
    $ berks install
    Resolving cookbook dependencies...
    Fetching 'myCookbook' from source at .
    Fetching cookbook index from https://supermarket.getchef.com...
    Installing maven (1.2.0)
    Installing 7-zip (1.0.2)
    Installing ark (0.9.0)
    Installing chef_handler (1.1.6)
    Installing java (1.29.0)
    Installing windows (1.34.8)
    Using myCookbook (0.1.0) from source at .
    

    Berkshelf can also upload all the cookbooks into your chef server

    $ berks upload
    Uploaded 7-zip (1.0.2) to: 'http://127.0.0.1:8889/'
    Uploaded ark (0.9.0) to: 'http://127.0.0.1:8889/'
    Uploaded chef_handler (1.1.6) to: 'http://127.0.0.1:8889/'
    Uploaded java (1.29.0) to: 'http://127.0.0.1:8889/'
    Uploaded maven (1.2.0) to: 'http://127.0.0.1:8889/'
    Uploaded myCookbook (0.1.0) to: 'http://127.0.0.1:8889/'
    Uploaded windows (1.34.8) to: 'http://127.0.0.1:8889/'
    
    0 讨论(0)
  • 2021-01-23 18:44

    There is a few other options for managing cookbook cookbook and dependencies, such Berkshelf or Librarian-chef, where Berkshelf is more popular, and it's even included in Chef Development Kit, so if you use it you do not need to install it separately.

    After defining sources you just need to define which cookbooks you want their versions and cookbook manager will resolve dependencies for all defined cookbooks and it will install them for you, and if you want you can vendor them too. Beside that they have an option to upload specific cookbook, without worrying about upload dependencies.

    For more info how to use those tools consult official websites:

    • http://berkshelf.com
    • https://github.com/applicationsonline/librarian-chef

    In general for managing small projects you can use knife's upload flag for uploading dependencies.

    -d, --include-dependencies
        Use to ensure that when a cookbook has a dependency on one (or more) cookbooks, those cookbooks will also be uploaded.
    
    0 讨论(0)
  • 2021-01-23 18:45

    See here

    Or just type knife cookbook upload --help and it will show you the following line (along others):

    --include-dependencies Also upload cookbook dependencies

    So knife cookbook upload myCookbook --include-dependencies is your answer

    You'll need to have the maven cookbook on your workstation too, by knife cookbook site install maven or any other way to have a directory called maven in your local cookbook_path containing a cookbook where the metatada.rb file as a key name with value maven

    0 讨论(0)
提交回复
热议问题