Git Product home page Git Product logo

chef-helpers's Introduction

Chef Helpers

This gem includes miscellaneous add-on helper methods for Opscode Chef.

Installation

To use helper methods in your Chef recipes, use following code in your recipe:

chef_gem 'chef-helpers'
require 'chef-helpers'

To use the helpers locally in knife exec scripts or Knife plugins, just add the chef-helpers gem to your dependencies and require 'chef-helpers'.

Usage

Detailed documentation of the helper methods can be seen at http://rdoc.info/github/3ofcoins/chef-helpers/

Finding existing templates and cookbook files

The recipe DSL is extended with ChefHelpers::HasSource module that provides methods for checking which templates and cookbook files exist on the Chef server. Detailed docs are available at http://rdoc.info/github/3ofcoins/chef-helpers/ChefHelpers/HasSource

Chef::Node#allies

The node.allies method returns an array of node's allies. These are: all nodes in the same environment (if the environment is not _default), plus nodes specified by allies attribute. The allies attribute - if set - should be an array of node names or node search queries; the named nodes and search results will be added to node's allies.

This is mostly useful when defining firewall or other access rules, to easily limit access to insides of a cluster plus a handful of friendly machines.

Chef::Node#ip_for

The node.ip_for(other_node) method decides, which IP address should the node use to contact the other node, and returns this IP as a string. It is particularly useful when your setup spans across cloud availability zones or different providers. At the moment only EC2 and nodes with public ipaddress are supported; suggestions are welcome.

If both nodes are on EC2 and in the same region, then other node's ec2.local_ipv4 attribute is used. Otherwise, if other node is a cloud instance, its cloud_public.ipv4 attribute is used. Otherwise, other node's ipaddress is used.

JSONPath access to attributes

The Chef::Node class is monkey-patched to allow easy deep access to the attributes using the JSONPath syntax:

chef > require 'chef-helpers'
 => true 
chef > node['$..name']
 => ["portinari-2.local", "Java(TM) SE Runtime Environment", "Java HotSpot(TM) 64-Bit Server VM", "Darwin"] 
chef > node['$.kernel.name']
 => ["Darwin"] 

Regular access to attributes is preserved; JSONPath is used only when the attribute name starts with $ character, or if a JSONPath instance is used for indexing.

The jsonpath gem is used for the implementation. While the original gem allows modification, it's not straightforward to achieve with Chef's attributes, so only reading attributes with JSONPath is supported.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

chef-helpers's People

Contributors

maoueh avatar mpasternacki avatar sonots avatar xamebax avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.