Code Monkey home page Code Monkey logo

hostsfile's Introduction

hostsfile LWRP

hostsfile provides an LWRP for managing your hosts file using Chef.

Requirements

At this time, you must have a Unix-based machine. This could easily be adapted for Windows machines. Please submit a Pull Request if you wish to add Windows support.

Attributes

Attribute Description Example Default
ip_address (name attribute) the IP address for the entry 1.2.3.4
hostname (required) the hostname associated with the entry example.com
aliases array of aliases for the entry ['www.example.com'] []
comment a comment to append to the end of the entry 'interal DNS server' nil

Actions

This LWRP comes equipped with 4 actions:

create

Creates a new hosts file entry. If an entry already exists, it will be overwritten by this one.

hostsfile_entry '1.2.3.4' do
  hostname 'example.com'
  action :create
end

This will create an entry like this:

1.2.3.4          example.com

create_if_missing

Create a new hosts file entry, only if one does not already exist for the given IP address. If one exists, this does nothing.

hostsfile_entry '1.2.3.4' do
  hostname 'example.com'
  action :create_if_missing
end

create_or_update

Create a new hosts file entry if not found. If exists appends given hostname to aliases.

hostsfile_entry '1.2.3.4' do
  hostname 'www.example.com'
  action :create_or_update
end

update

Updates the given hosts file entry. Does nothing if the entry does not exist.

hostsfile_entry '1.2.3.4' do
  hostname 'example.com'
  comment 'Update by Chef'
  action :update
end

This will create an entry like this:

1.2.3.4           example # Updated by Chef

remove

Removes an entry from the hosts file. Does nothing if the entry does not exist.

hostsfile_entry '1.2.3.4' do
  action :remove
end

This will remove the entry for 1.2.3.4.

Usage

Download or install this cookbook from the community site:

$ knife cookbook site install hostsfile

Then, simply include this recipe and you'll be granted access to this LWPR:

# your_recipe.rb
include_recipe 'hostsfile'

Contributing

  1. Fork the project
  2. Create a feature branch corresponding to you change
  3. Commit and test thoroughly
  4. Create a Pull Request on github
    • ensure you add a detailed description of your changes

License and Authors

Authors: Seth Vargo (@sethvargo)

Copyright 2012, CustomInk, LLC

hostsfile's People

Contributors

sethvargo avatar bavovna avatar

Stargazers

Zack Zondlo avatar

Watchers

James Cloos 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.