Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

node-ansible

shaharke8.9kMIT0.5.5

Programmatic interface in Node.js for executing Ansible ad-hoc commands and playbooks

ansible, api, programmatic

readme

node-ansible Build Status

Programmatic interface in Node.js for executing Ansible ad-hoc commands and playbooks

Warning: this package is still under development. API might break between minors.

Installation

npm install node-ansible --save

NOTE: I think it goes without saying, but I'll mention it anyway - you MUST have ansible installed on the same machine on which your node process is going to run.

Crash Course

var Ansible = require('node-ansible');
var command = new Ansible.AdHoc().module('shell').hosts('local').args("echo 'hello'");
command.exec();

is equivalent to:

ansible local -m shell -a "echo 'hello'"
var playbook = new Ansible.Playbook().playbook('my-playbook');
playbook.exec();

is equivalent to:

ansible-playbook myplaybook.yml

Let's execute:

var promise = playbook.exec();
promise.then(function(successResult) {
  console.log(successResult.code); // Exit code of the executed command
  console.log(successResult.output) // Standard output/error of the executed command
}, function(error) {
  console.error(error);
})

We can also get the results of a command streamed in real time (from both playbooks and adhoc commands):

playbook.on('stdout', function(data) { console.log(data.toString()); });
playbook.on('stderr', function(data) { console.log(data.toString()); });
var promise = playbook.exec();

Full Documentation

Running tests:

npm test

License

MIT

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

[Unreleased]

0.5.4 - 2015-12-19

Added

  • #22 Add command option for --private-key

0.5.3 - 2015-12-19

Added

  • #17 Emit 'close' event when the command completes
  • CHANGELOG.md for tracking changes between versions