Git Product home page Git Product logo

hiera-mysql-backend's Introduction

Gem Version

hiera-mysql-backend

Alternate MySQL backend for Hiera

This is a MySQL backend for Hiera inspired by hiera-mysql. Unfortunately no work has been done to that backend for the past 9 months and it was missing a couple of features I needed so I decided to pick up the torch and implement them myself.

What is different from hiera-mysql

In hiera-mysql you define the queries in the hiera.yaml file. I felt this was too restricting so instead hiera-mysql-backend uses, poorly named, sql files. This sql files follow the Hiera hierarchy.

hiera-mysql would also return the last matching query not the first one which I felt it was confusing.

hiera-mysql used the mysql gem, I am partial to mysql2

Exception handling. hiera-mysql would cause a puppet run to fail if one of the queries was incorrect. For example a fact that you are distributing with a module is needed for the query to return its data but that fact is not available outside the module having a SELECT * from %{custom_fact} would make puppet runs fail.

What goes into the sql files.

The poorly named sql files are really yaml files where the key is the lookup key and the value is the SQL statement (it accepts interpolation)

As of version 0.0.4 you can also add connection information to these sql files, this allows you to connect to different databases. This is optional if no connection information is found it will use the default defined in your hiera.yaml config.

Lets assume your datadir is /etc/puppet/hieradata/ and your hierarchy for hiera just have a common. hiera-mysql-backend would look for /etc/puppet/hieradata/common.sql the common.sql would look like:

---
# This is optional, if not present it will use the default connection info from hiera.yaml
:dbconfig:
  :host: database.example.com
  :user: hieratest
  :pass: sekret
  :database: testhieradb
  :port: 44445

applications: SELECT * FROM applications WHERE host='%{fqdn}';
coats: SELECT cut,name,type FROM coats WHERE color='brown';

If host is not defined it will use localhost as default.

If port is not defined it will use the default 3306 mysql port

running hiera applications would run the query against the configured database.

Using

gem install hiera-mysql-backend

Configuring Hiera

Hiera configuration is pretty simple

---
:backends:
  - yaml
  - mysql2

:yaml:
  :datadir: /etc/puppet/hieradata

:mysql2:
  :datadir: /etc/puppet/hieradata
  :host: hostname
  :user: username
  :pass: password
  :database: database
  :port: 3306

:hierarchy:
  - "%{::clientcert}"
  - "%{::custom_location}"
  - common

:logger: console

If host is not defined it will use localhost as default.

If port is not defined it will use the default 3306 mysql port

Known issues

  1. It always return an Array of hashes regardless of the number of items returned. (I did this on purpose because it is what I needed but I may be persuaded to do otherwise)
  2. This README is poorly written.

Contributing

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

hiera-mysql-backend's People

Contributors

telmo avatar

Watchers

Mattias Geniar avatar Wouter D'Haeseleer avatar James Cloos avatar  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.