Giter VIP home page Giter VIP logo

go-ansible-db's Introduction

go-ansible-db

Go Report Card

Ansible Inventory and Vault management client library written in Go.

Table of Contents

Overview

Ansible inventory and secrets management is being handled well by native Ansible tools. The inventory format is well defined and the vault usage is well understood. Ansible is written in Python and therefore integrates nicely with Python code.

What happens when a user wants to read inventory and secrets for use in Go applications?

This library allows:

  • Reading Ansible ini-style inventory files
  • Reading Ansible vault files
  • Getting Ansible variables for a host or a group of hosts
  • Getting Ansible secrets (credentials) for a host or a group of hosts

Getting Started

To demonstrate the use of the library, please consider the following files:

  • assets/inventory/hosts: Ansible inventory file
  • assets/inventory/vault.yml: Ansible vault file
  • assets/inventory/vault.key: The file with the password for the vault

The following code snippet would load the inventory and vault content.

invFile := "../../assets/inventory/hosts"
vltFile := "../../assets/inventory/vault.yml"
vltKeyFile := "../../assets/inventory/vault.key"

// Create a new inventory file.
inv := NewInventory()
// Load the contents of the inventory from an input file.
if err := inv.LoadFromFile(invFile); err != nil {
    t.Fatalf("error reading inventory: %s", err)
}

// Create a new vault file.
vlt := NewVault()
// Read the password for the vault file from an input file.
if err := vlt.LoadPasswordFromFile(vltKeyFile); err != nil {
    t.Fatalf("error reading vault key file: %s", err)
}
// Load the contents of the vault from an input file.
if err := vlt.LoadFromFile(vltFile); err != nil {
    t.Fatalf("error reading vault: %s", err)
}

Inventory Search

After that, the code retrieves the inventory record for ny-sw01 and makes a subsequent call to retrieve the credentials for accessing ny-sw01.

h := "ny-sw01"
host, err := inv.GetHost(h)
if err != nil {
    t.Fatalf("error getting host %s from inventory: %s", h, err)
}
creds, err := vlt.GetCredentials(host.Name)
if err != nil {
    t.Fatalf("error getting credentials for host %s: %s", host.Name, err)
}

go-ansible-db's People

Contributors

greenpau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-ansible-db's Issues

Should groups be "exclusive"?

In a test, I got the message AddHost() failed: host p1s10.dcaux.indexww.com exists in multiple groups: zookeeper-nodes, dc1-stats, line: 1091

The machine was supposed to be in two groups, dc1-stats, with a specific task of providing zookeeper services, and our ansible seem to process it correctly.

Should the library be alerting on this?

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.