dodin

package module
v0.0.0-...-09313d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2016 License: MIT Imports: 6 Imported by: 0

README

Circle CI Go Report Card

dodin - dynamic inventory provider for Ansible

Currently only Digital Ocean is supported, but contributions are welcome to enable it for other providers too. Ping me and I will help you to start up the development environment.

Features:

  • Group droplets by name with regular expression;
  • Unlimited custom groups;
  • Add variables to groups;
  • Display full information for each droplet with --host hostname flag (by droplet name);
  • Ability to generate static inventory file with extra flag.

What is dodin for?

Ansible provides neat option to use to use dynamic inventories, instead of static inventory files. It is useful when managing dynamic infrastructure, where static inventory file would need to be constantly modified in order to keep it up with nodes in the cloud.

How to install dodin?

  1. There is no binary distributed, so you have to have a golang runtime in order to use it;
  2. Download sources and compile it via go get github.com/asarturas/dodin/cmd/dodin-digital-ocean.

How to use dodin?

  1. In your project directory create dodin-digital-ocean.ini file, where you define group hosts with regular expression and list group variables in a same way as you do with static inventories:

    [master]
    members=master\-[0-9]{2}
    
    [master:vars]
    ansible_ssh_user=core
    ansible_python_interpreter="PATH=/home/core/bin:$PATH python"
    
    [minion]
    members=minion\-[0-9]{2}
    
    [minion:vars]
    ansible_ssh_user=core
    ansible_python_interpreter="PATH=/home/core/bin:$PATH python"
    
  2. Export your digital ocean api token like this export DO_API_TOKEN=1234567890;

  3. Check dodin works correctly via $GOPATH/bin/dodin-digital-ocean, it should output json with all your nodes in all group;

  4. Ping cluster hosts via ansible cluster -m ping -i "$GOPATH/bin/dodin-digital-ocean".

Why use dodin?

Unfortunately standard provided scripts are not very flexible. For instance, when you have coreos cluster with 3 master and 3 minion hosts, then without script modification you would not be able to group nodes logically nor you will be able to add custom variables the way you would do in static inventory file:

[master]
master-01
master-02
master-03

[master:vars]
ansible_ssh_user=core
ansible_python_interpreter="PATH=/home/core/bin:$PATH python"

[minion]
minion-01
minion-02
minion-03

[minion:vars]
ansible_ssh_user=core
ansible_python_interpreter="PATH=/home/core/bin:$PATH python"

For such infrastructure standard digital ocean dynamic inventory script digital_ocean.py would group them operating system, size, region and put each in separate group by name and id. The output would be like this:

{
    "12190784": ["178.62.29.42"],
    "distro_CoreOS": ["178.62.29.42", "188.166.150.62", "178.62.95.186", "178.62.96.225", "178.62.117.116", "46.101.5.85"],
    "master-01": ["178.62.29.42"],
    "size_512mb": ["178.62.29.42", "188.166.150.62", "178.62.95.186", "178.62.96.225", "178.62.117.116", "46.101.5.85"],
    "region_lon1": ["178.62.29.42", "188.166.150.62", "178.62.95.186", "178.62.96.225", "178.62.117.116", "46.101.5.85"],
    "12190825": ["178.62.117.116"],
    "12190827": ["46.101.5.85"],
    "status_active": ["178.62.29.42", "188.166.150.62", "178.62.95.186", "178.62.96.225", "178.62.117.116", "46.101.5.85"],
    "12190824": ["178.62.96.225"],
    "12190787": ["188.166.150.62"],
    "image_coreos-alpha": ["178.62.29.42", "188.166.150.62", "178.62.95.186", "178.62.96.225", "178.62.117.116", "46.101.5.85"],
    "minion-03": ["46.101.5.85"],
    "minion-01": ["178.62.96.225"],
    "master-02": ["188.166.150.62"],
    "master-03": ["178.62.95.186"],
    "image_16335999": ["178.62.29.42", "188.166.150.62", "178.62.95.186", "178.62.96.225", "178.62.117.116", "46.101.5.85"],
    "minion-02": ["178.62.117.116"],
    "12190789": ["178.62.95.186"]
}

Dodin allows you to replicate that example static inventory file with simple ini config, which looks very similar to original. The only difference that instead of listing all the hostnames in group, we're specifying regular expression pattern to match node name:

[master]
members=master\-[0-9]{2}

[master:vars]
ansible_ssh_user=core
ansible_python_interpreter="PATH=/home/core/bin:$PATH python"

[minion]
members=minion\-[0-9]{2}

[minion:vars]
ansible_ssh_user=core
ansible_python_interpreter="PATH=/home/core/bin:$PATH python"

This given example would put into master group any node named master-00 to master-99. Similarly it would put minion-00 to minion-99. Note that variables are defined the same way as they would in static file. The dodin-digital-ocean would output:

{
    "master": {
        "hosts":
            ["178.62.29.42","188.166.150.62","178.62.95.186"],
        "vars": {
            "ansible_python_interpreter":"PATH=/home/core/bin:$PATH python",
            "ansible_ssh_user":"core"
        }
    },
    "minion": {
        "hosts":
            ["178.62.96.225","178.62.117.116","46.101.5.85"],
        "vars": {
            "ansible_python_interpreter":"PATH=/home/core/bin:$PATH python",
            "ansible_ssh_user":"core"
        }
    }
}

Which is equivalent of the first one, but in dynamic format, expected by ansible-playbook.

Disclaimer

The software is provided as is. I use it and am happy to help you setup or to resolve any issues with it, but you are taking all the responsility for using it.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func ParseConfig

func ParseConfig(configFileContents string) Config

func (Config) Groups

func (config Config) Groups() []GroupConfig

type ConfigFileProvider

type ConfigFileProvider struct {
	Filename string
}

func (ConfigFileProvider) Get

func (provider ConfigFileProvider) Get() Config

type ConfigProvider

type ConfigProvider interface {
	Get() Config
}

type FakeConfigProvider

type FakeConfigProvider struct {
	// contains filtered or unexported fields
}

func (FakeConfigProvider) Get

func (provider FakeConfigProvider) Get() Config

type Group

type Group struct {
	// contains filtered or unexported fields
}

func FromMatchingMachines

func FromMatchingMachines(config GroupConfig, machines []cloud.Machine) Group

func (Group) Members

func (group Group) Members() []cloud.Machine

func (Group) Name

func (group Group) Name() string

func (Group) Variables

func (group Group) Variables() map[string]string

type GroupConfig

type GroupConfig struct {
	// contains filtered or unexported fields
}

func NewGroupConfig

func NewGroupConfig(name, memberNamePattern string, variables map[string]string) GroupConfig

func (GroupConfig) MatchingMemberName

func (config GroupConfig) MatchingMemberName(name string) bool

func (GroupConfig) Name

func (config GroupConfig) Name() string

func (GroupConfig) Variables

func (config GroupConfig) Variables() map[string]string

type Inventory

type Inventory struct {
	// contains filtered or unexported fields
}

func BuildInventoryFrom

func BuildInventoryFrom(machines []cloud.Machine, config Config) Inventory

func Dodin

func Dodin(configProvider ConfigProvider, cloudProvider cloud.Provider) Inventory

func (Inventory) String

func (inventory Inventory) String() string

type InventoryGroup

type InventoryGroup struct {
	Hosts []string          `json:"hosts"`
	Vars  map[string]string `json:"vars"`
}

Directories

Path Synopsis
do
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL