hcloudinventory

package module
v0.0.0-...-e97c05e Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2018 License: MIT Imports: 8 Imported by: 0

README

Ansible Inventory for Hetzner Cloud

CircleCI Go Report Card GoDoc

Automate your Hetzner Cloud instances by using a dynamic inventory script for Ansible.

See it in action

Getting Started

See Getting Started in the repository's wiki. Here you will find always up-to-date installation instructions as well as remarks concerning the configuration and usage of the inventory script.

Usage

You are able to use the within your Ansible commands using the -i flag.

HETZNER_CLOUD_KEY=example ansible -i hcloud-ansible-inv all -m ping

This command should execute the Ansible ping module and should return a pong for each server you are running at Hetzner Cloud. Please consult Ansible's documentation for further resources concerning the usage of Ansible itself.

License

This project is open source (MIT License). For more information see LICENSE.

Acknowledgements

This project is using the Hetzner Cloud API Client and jeffail's Gabs (painless JSON processing).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultGrouper

type DefaultGrouper struct {
	// GroupMappings is a mapping of hosts, like group => host1, host2 ...
	GroupMappings map[string][]string
}

DefaultGrouper is the default implementation of Grouper

func (*DefaultGrouper) GroupsForHost

func (s *DefaultGrouper) GroupsForHost(hostname string) (groupNames []string)

GroupsForHost will return any groups that the host is a part of

func (*DefaultGrouper) LoadYaml

func (s *DefaultGrouper) LoadYaml(fileName string)

LoadYaml loads a YAML file and tries to Unmarshal it into the GroupMappings type

type GroupDefinition

type GroupDefinition struct {
	Hosts    []string               `json:"hosts"`
	Vars     map[string]interface{} `json:"vars,omitempty"`
	Children []string               `json:"children,omitempty"`
}

GroupDefinition is used to define a group of hosts

type Grouper

type Grouper interface {
	// GroupsForHost should return any groups that the host is a part of
	GroupsForHost(hostname string) (groupNames []string)
}

Grouper is an interface for the grouping of hosts

type Host

type Host struct {
	Name   string
	Groups []string
}

Host is a tool struct to let Inventory keep track of groups

type HostVars

type HostVars struct {
	IP         string `json:"ansible_host"`
	DNS        string `json:"hcloud_dns"`
	Location   string `json:"hcloud_location"`
	Datacenter string `json:"hcloud_datacenter"`
	Image      string `json:"hcloud_image"`
}

HostVars is host specific variables to be stored in meta

type Inventory

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

Inventory is the main struct which will be returned as a result of GetInventoryFromAPI

func GetInventoryFromAPI

func GetInventoryFromAPI(client ServerClient, grouper Grouper) *Inventory

GetInventoryFromAPI returns a JSON-formatted and Ansible-compatible representation of all virtual servers that are listed under the specified Hetzner Cloud API account.

func (*Inventory) AddHost

func (s *Inventory) AddHost(host *Host)

AddHost will add a Host to the inventory

func (*Inventory) Group

func (s *Inventory) Group(name string) *GroupDefinition

Group is used for getting and/or creating a group for storing hosts

func (*Inventory) JSON

func (s *Inventory) JSON() (jsonString string)

JSON will output a json representation of the Inventory

func (*Inventory) SetMeta

func (s *Inventory) SetMeta(meta *Meta)

SetMeta will set the meta field of the inventory

func (*Inventory) UpdateAllGroup

func (s *Inventory) UpdateAllGroup()

UpdateAllGroup will refresh the Inventory group named all

type Meta

type Meta struct {
	Hostvars map[string]*HostVars `json:"hostvars"`
}

Meta is the _meta tag in the resulted Inventory

type ServerClient

type ServerClient interface {
	All(ctx context.Context) ([]*hcloud.Server, error)
}

ServerClient is an interface for allowing mocking in tests

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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