ansible-playbook-cli-js
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

ansible-playbook-cli-js

A node.js wrapper for the ansible-playbook command

NPM NPM

NPM version NPM downloads

Installation

Step 1: Prerequisites

Ansible must be installed and accessible in the path

Step 2: Installation

npm install ansible-playbook-cli-js

Then:

var ansiblePlaybookCli = require('ansible-playbook-cli-js');

Usage

With promise

var Options = ansiblePlaybookCli.Options;
var AnsiblePlaybook = ansiblePlaybookCli.AnsiblePlaybook;
 
var options = new Options(
    /* currentWorkingDirectory */ 'test'
);
 
var ansiblePlaybook = new AnsiblePlaybook(options);
 
 
ansiblePlaybook.command('playbook.yml -i hosts').then(function (data) {
  console.log('data = ', data); 
});
 
 
//data = {
//  command: 'ansible-playbook playbook.yml -i hosts ',
//  raw: '\\nPLAY [create test dir] ******************************************************** \\n\\nGATHERING FACTS *************************************************************** \\nok: [127.0.0.1]\\n\\nTASK: [create tmp2 dir] ******************************************************* \\nok: [127.0.0.1]\\n\\nPLAY RECAP ******************************************************************** \\n127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0   \\n\\n',
//  lines:
//   ['',
//     'PLAY [create test dir] ******************************************************** ',
//     '',
//     'GATHERING FACTS *************************************************************** ',
//     'ok: [127.0.0.1]',
//     '',
//     'TASK: [create tmp2 dir] ******************************************************* ',
//     'ok: [127.0.0.1]',
//     '',
//     'PLAY RECAP ******************************************************************** ',
//     '127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0   ',
//     '',
//     ''],
//  object: { host: '127.0.0.1', ok: 2, changed: 0, unreachable: 0, failed: 0 }
//}
 

With callback:

 
ansiblePlaybook.command('playbook.yml --inventory-file hosts', function (err, data) {
  console.log('data = ', data);
});
 
 

Typescript:

import { AnsiblePlaybook, Options } from 'ansible-playbook-cli-js';
 
const options = new Options(
  /* currentWorkingDirectory */ 'test'
);
 
const ansiblePlaybook = new AnsiblePlaybook(options);
 
ansiblePlaybook.command('playbook.yml --inventory-file hosts').then(function (data) {
  console.log('data = ', data);
});
 

License

MIT

Dependents (0)

Package Sidebar

Install

npm i ansible-playbook-cli-js

Weekly Downloads

18

Version

2.0.5

License

MIT

Unpacked Size

12.9 kB

Total Files

6

Last publish

Collaborators

  • mattqs