# ansibleapi

> Execute commands on the Ansible server

Latest version **1.2.0** (published 2016-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install ansibleapi
pnpm add ansibleapi
yarn add ansibleapi
bun add ansibleapi
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2016-06-21 |
| First published | 2016-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ~4.4.4 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Don Payne |
| Maintainers | donpayne |

## Links

- npm: https://www.npmjs.com/package/ansibleapi
- Repository: https://github.com/donpayne/ansibleapi
- Issues: https://github.com/donpayne/ansibleapi/issues
- npm.io page: https://npm.io/package/ansibleapi

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.0

## Recent versions

- 1.2.0 (latest) — 2016-06-21

## README

# Ansible API
============
This is a programmatic interface in NodeJS for executing Ansible ad-hoc commands and playbooks

## Installation

### npm

Install the module via npm specifying a version.

	$ npm install ansibleapi --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.

### Running AdHoc Commands

The Ansible object contains an AdHoc method that mimics the cli commands.

	var Ansible = require('ansibleapi');
	var command = Ansible.AdHoc().module('shell').hosts('local').args("echo 'hello'");
	command.exec();

This is equivalent to the following shell command:

	ansible local -m shell -a "echo 'hello'"

The exec method returns a promise that can provide status codes and output asynchronously

	var promise = command.exec();
	promise.then(function (result)
	{
		console.log(result.code);  // Exit code of the executed command
		console.log(result.output) // Standard output/error of the executed command
	}, function (error)
	{
		console.error(error);
	});

### Running Playbooks

The Ansible object contains a Playbook method that mimics the cli commands.

	var Ansible  = require('ansibleapi');
	var playbook = Ansible.Playbook().playbook('myplaybook');
	playbook.exec();

This is equivalent to the following shell command:

	ansible-playbook myplaybook.yml

The exec method returns a promise that can provide status codes and output asynchronously

	var promise = playbook.exec();
	promise.then(function (result)
	{
		console.log(result.code);  // Exit code of the executed command
		console.log(result.output) // Standard output/error of the executed command
	}, function (error)
	{
		console.error(error);
	});

### Realtime Streaming

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();

---
_Source: https://npm.io/package/ansibleapi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
