• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    CSS
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ansible playbook automation server

Ansijet

Build Status

An Ansible playbook automation server.

A node.js server which exposes a simple web API which triggers playbook runs when a request is received. This is especially useful if you are unable to run Ansible playbooks directly from within your continuous integration environment or if you simply wish to trigger playbook runs based on other events within your system.

Features:

  • Trigger playbook runs from different sources, including from CI systems such as Drone.
  • Run multiple playbooks in parallel, all in separate processes
  • Fast, friendly web interface with accompanying REST API
  • Highly asynchronous, scalable back-end
  • Full console log capture and storage
  • Sends notifications of job status through HipChat

Installation and startup

Pre-requisite: Ansible 1.5+

Installation instructions: http://docs.ansible.com/intro_installation.html.

To ensure you have the latest version it is recommended that you install it using pip, the Python package manager.

Pre-requisite: Node.js 0.11.2+

Installation instructions: http://nodejs.org/.

Ensure the installed version is at least 0.11.2. Ansijet will not work with earlier versions.

(For Ubuntu users I recommend the Chris Lea PPA).

Pre-requisite: MongoDB

Installation instructions:

Ansijet stores its data in MongoDB. The default configuration expects to be able to connect to a MongoDB server running on 127.0.0.1 (i.e. localhost).

Setup your Ansible playbooks

Place your Ansible playbooks somewhere, e.g. /playbooks.

Ansijet expects your playbooks folder to have a certain structure:

<playbooks folder>/*.yml   <- your playbooks
<playbooks folder>/hosts   <- Ansible hosts file

Ensure that any roles needed by your playbooks can be found by the ansible-playbook binary. An easy way to ensure this is to store your roles within the same folder, i.e. at <playbooks folder>/roles/. Ditto for group_vars and host_vars folders.

Setup Ansijet

$ git clone https://github.com/hiddentao/ansijet.git ansijet
$ cd ansijet
$ npm install -g gulp bower
$ npm install
$ bower install
$ npm run build

Now create ansijet/src/config/production.js:

"use strict";

module.exports = function(config) {
  /** Path to folder containg Ansible playbooks */
  config.playbooks = '/playbooks'

  /** Max no. of jobs to execute in parallel. Should match no. of CPU cores. */
  config.jobsInParallel = 1;
};

If you look inside ansijet/src/config/base.js you will see other configuration settings MongoDB, logging, etc. You may override these too within the config/production.js you created.

Run Ansijet

$ cd ansijet
$ NODE_ENV=production ./start-app.js

If you visit http://localhost:3000 you should see the dashboard showing the Active Jobs (there should be none currently).

Setup playbook automation

Once Ansijet is up and running and you can access the web interface you can view the list of Playbooks that Ansijet has found and assign triggers to them.

Triggers

A trigger is a mechanism which kicks of a playook run when an incoming URL request is received.

Triggers have two purposes:

  1. To perform any necessary additional checks when a request is received to ensure that the request is valid
  2. To supply variables to the Ansible playbook, allowing for playbook execution to be configurable based on the incoming request and the trigger configuration.

All triggers URLs look like /invoke/<trigger id>?token=<secret token> with additional query parameters depending on the trigger type.

Note: The <secret token> is randomly generated by Ansijet when a trigger is created and acts as an additional security check. If the token in an incoming request is incorrect Ansijet does not report this to the URL requester - it simply logs this fact in the back-end.

At present two trigger types are supported:

Trigger: Simple

This exposes a simple URL which triggers a playbook run. It does not perform any checks prior to triggering the playbook run. Neither does it supply any Ansible playbook variables.

Trigger: Drone

This exposes a URL to be called after a successful Drone build. It supplies the following Ansible variables:

  • ci_expected_branch <- Git branch to run playbook for, configured by user
  • ci_build_commit <- Git commit id, obtained from incoming request
  • ci_build_branch <- Git branch built, obtained from incoming request

Jobs

When a trigger is invoked it runs a playbook, known as a Job. Jobs are executed in parallel by Ansijet, with the maximum no. of simultaenous jobs determined by the jobsInParallel configuration parameter set during Ansijet installation. Ansijet is also smart enough to ensure that for each playbook, only one instance of it is being run at a time.

Each job - i.e. playbook run - takes place in a separate shell process, allowing Ansijet to be scaled up according to your machine's cores. Ansijet also monitors each shell process such that if no output is received for 5 minutes (this time window is configurable) it will kill the shell process and assume the playbook run has failed.

When a job is being processed it shows up as an Active Job on your Ansijet server's homepage. You can click on it to view the current log output, including console log output.

Execution logs

All logs can be viewed by going to the Logs site section. You can then drill down to view the logs pertaining to a particular trigger and/or a particular trigger job.

REST API

Ansijet is built using Waigo, which means that all the URL routes automatically have REST API counterparts. For any given URL, you can view REST JSON output by simply appending a format=json query parameter when making the request. This applies to form submissions too. For more information on this see the Waigo docs.

HipChat

Ansijet can be configured to send notifications to a HipChat room using the send_room_notification API.

Simply add the room id and auth token to your configuration file:

module.exports = function(config) {
  ...
  config.notifications.hipChat = {
    roomId: <room id>,
    authToken: <auth token for room>
  };
  ...
};

When Ansijet first starts up it will send a notification. Subsequent notifications will get sent for every job which gets processed.

Securing Ansijet

Ansijet does not come with any sort of authentication out of the box. Since it's running playbooks which most probably affect your servers you will likely want to protect access to it.

My setup is to have Ansijet placed behind an Nginx front-end server, with SSL and HTTP Basic auth enforced on all incoming requests:

server {
  listen 80;
  server_name example.com www.example.com;
  return 301 https://$host$request_uri;
}

server {
  listen 443;
  server_name example.com www.example.com;

  ssl on;
  ssl_certificate /etc/ssl/certs/server.crt;
  ssl_certificate_key /etc/ssl/private/server.key;
  ssl_session_timeout 5m;

  # Perfect Forward Secrecy
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA256:EECDH+aRSA+RC4:EDH+aRSA:EECDH:RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS;

  root /ansijet/frontend/build;

  location ~ /\. {
    deny all;
  }

  location ~* ^/(css|fonts|img|js)/.+$ {
    gzip_static on;
    gzip_vary on;
    expires 30d;
    add_header Pragma public;
    add_header Cache-Control "public";
  }

  location ~* ^(robots|humans)\.txt$ {
    expires 30d;
    add_header Pragma public;
    add_header Cache-Control "public";
  }

  # If you want to monitor the status of Ansijet and check that it is running 
  # you can call the `/ping` URL. This will output `Ansijet up` is Ansijet is 
  # running
  location = /ping {
    proxy_pass http://127.0.0.1:3000;
  }

  # Everything else needs auth
  location / {
    auth_basic on;
    auth_basic_user_file /ansijet/httpd.auth;
    proxy_pass http://127.0.0.1:3000;
  }

}

Contributing

Though I am already using Ansijet in a production environment it is very much a work-in-progress. All suggestions and pull requests are welcome!

See CONTRIBUTING.md for guidelines.

License

MIT - see LICENSE.md

More Repositories

1

squel

๐Ÿข SQL query string builder for Javascript
CoffeeScript
1,566
star
2

fast-levenshtein

Efficient Javascript implementation of Levenshtein algorithm with locale-specific collator support.
JavaScript
580
star
3

google-tts

Javascript API for the Google Text-to-Speech engine
JavaScript
312
star
4

robe

MongoDB ODM for Node.js using ES6 generators. Supports schema validation, raw querying, oplog tailing, etc.
JavaScript
178
star
5

linear-algebra

Efficient, high-performance linear algebra for node.js and browsers
JavaScript
162
star
6

melkor

Wiki powered by Node.js and Git
JavaScript
149
star
7

react-native-modal-filter-picker

Cross-platform modal picker for React Native which supports keyword filtering, custom rendering, etc
JavaScript
104
star
8

gulp-server-livereload

Gulp plugin to run a local webserver with livereload enabled via socket.io. Also comes with standalone command-line interface.
JavaScript
92
star
9

cordova-plugin-filepath

Resolve native file paths from content URLs for Cordova platforms
Java
66
star
10

geth-private

Quickly setup a local, private Ethereum blockchain.
JavaScript
60
star
11

ethereum-abi-ui

Auto-generate UI form field definitions and associated validators from an Ethereum contract ABI
JavaScript
58
star
12

ethereum-event-logs

Ethereum event logs parser
JavaScript
48
star
13

browsermail

Javascript IMAP email client for browsers
JavaScript
47
star
14

mailmask

Mailmask - easy stop unwanted email. Unlimited, free temporary email addresses, all forwarding to your real email address. Beat spam, protect your privacy.
JavaScript
39
star
15

lzw-async

Asynchronous Javascript implementation of LZW compression algorithm
HTML
38
star
16

wp-flickr-embed

Insert Flickr images into your Wordpress posts using an interactive interface
PHP
19
star
17

gulp-bench

Gulp plugin for running performance benchmarks
JavaScript
17
star
18

react-image-holder

React image component with offline placeholder fallbacks
JavaScript
17
star
19

koa-session-mongo

MongoDB storage layer for Koa session middleware
JavaScript
16
star
20

ethval

Easier calculation and formatting of Ethereum values
JavaScript
16
star
21

weber

Compile scripts, stylesheets and templates on-the-fly for rapid iterations
CoffeeScript
14
star
22

ethereum-contracts

Robust Ethereum contracts wrapper for easier deployment, method invocation and automatic type conversion.
JavaScript
14
star
23

clockmaker

Flexible Javascript timers which can be paused and modified on-the-fly
JavaScript
13
star
24

react-native-advanced-forms

Flexible React Native architecture for building and managing forms
JavaScript
13
star
25

koa-session-store

Session middleware for Koa with a pluggable storage layer
JavaScript
12
star
26

simple-mongo-schema

DEPRECATED. An easy-to-write schema validator for Mongo JSON objects
JavaScript
12
star
27

sjv

๐Ÿšฆ An easy-to-write schema and deep validator for JSON documents
JavaScript
11
star
28

ethereum-blocks

Process blocks from Ethereum client nodes robustly. Catch-up on restart, auto-reconnect to node, etc.
JavaScript
11
star
29

git-pull-cron

Git clone a repo into a folder and then schedule a cronjob to git pull updates
JavaScript
10
star
30

machine-learning

High-performance machine learning library for node.js and browsers
JavaScript
8
star
31

jquery.ajaxprogress

jQuery AJAX Progress plugin
JavaScript
8
star
32

drush_simpletest_command

An improved Drush SimpleTest command which allows you to run a single Drupal test from the command-line
7
star
33

elrond-voting-contract

Commit-reveal voting contract written in Rust for Elrond VM
Rust
6
star
34

page-tagger

A Wordpress plugin which lets you tag your pages just like you do with your posts
PHP
6
star
35

immutable-state-machine

Immutable state machine for Javascript with ability to associate extra data with each state. Useful for React.
JavaScript
6
star
36

askthensa

http://askthensa.com
5
star
37

ethereum-token-sales

Various Ethereum token sale contracts
5
star
38

mongo-replica-set

Command-line tool and API for setting up MongoDB replica sets on localhost
JavaScript
5
star
39

cron-async

Execute something on a schedule, using cron syntax, with async/await support.
TypeScript
4
star
40

patterns2

An improved version of the Drupal Patterns module.
PHP
4
star
41

es6-slides

Slides on the new features in Javascript ES6
JavaScript
4
star
42

react-native-extended-stylesheet-breakpoints

Smart responsive @media query generation for react-native-extended-stylesheets using configurable breakpoints
JavaScript
4
star
43

opengraph_meta

Drupal module which adds Open Graph meta tags to node pages for better social network sharing (e.g. http://developers.facebook.com/docs/share)
PHP
3
star
44

mocha-ci-slack-reporter

Slack reporter for Mocha when running in CI environments
JavaScript
2
star
45

ois-incidents-map

Officer-involved Shootings map of the USA
JavaScript
2
star
46

react-hooks

A collection of useful React hooks for async programming, web3, etc
TypeScript
2
star
47

node-generator-perf-tests

Some performance tests for when using generators in node.js
JavaScript
2
star
48

zhongwen

The source code to the zhongwen.co.uk website
JavaScript
2
star
49

ethanol

Desktop Solidity IDE **Work in progress**
JavaScript
2
star
50

react-native-xcode-packager

Custom XCode packager script for react-native which ensure bundle always gets built
Shell
2
star
51

logarama

Logging for the browser, logging levels, hierarchical child loggers, smart formatting, etc
JavaScript
2
star
52

documentation-lite

Extract JSDoc documentation from ES5/ES6 files into a JSON output structure.
JavaScript
2
star
53

us_latlng_json

JSON dataset of latitude and longitude co-ordinates for USA state counties and cities
2
star
54

abide

Base class with pub-sub and observers for JS object properties using ECMA5 getters/setters
JavaScript
2
star
55

genomatic

Utility methods for working with Generator functions, such as bind(), is(), etc
JavaScript
1
star
56

ethgoal

Goal achievement powered by Ethereum
JavaScript
1
star
57

phonegap-demo-app

CSS
1
star
58

indium

Reactive web framework for Node.js utilising RethinkDB and ReactJS
1
star
59

updates_notifier

Redmine plugin which update notifications to a callback URL when changes are made within Redmine
Ruby
1
star
60

saffronvideo

A Drupal module to make it easy to use Saffron media server assets.
PHP
1
star
61

smart-solidity-docs

Getting to grips with the Solidity programming language for the Ethereum blockchain
1
star
62

docjam

Javascript ES6 documentation extractor using markdown and jsdoc
JavaScript
1
star
63

method-mocks

Works with existing mocking and testing frameworks (e.g. Jest) to make method mocking easier.
JavaScript
1
star
64

hiddentao.com

HiddenTao website
JavaScript
1
star
65

nodejs-intro

Introduction to Node.js - building a chatroom using ExpressJS and Socket.IO
JavaScript
1
star
66

i21n

Tiny internationalization library for Node and the Browser
JavaScript
1
star
67

bulksms

BulkSMS API for TextAnywhere service
PHP
1
star
68

calc

Simple HTML5 calculator
HTML
1
star
69

uc_bulk_stock_updater

This is a Ubercart (Drupal) extension module which enables you to easily product stock levels on one page.
JavaScript
1
star
70

latlong-route-cleaner

Simple PHP script for cleaning out bad lat-long points form a driving route
PHP
1
star