2017 © Pedro Peláez
 

project ansible-wrapper-bundle

A Symfony wrapper for Ansible, providing launcher, events...

image

lucbu/ansible-wrapper-bundle

A Symfony wrapper for Ansible, providing launcher, events...

  • Thursday, November 17, 2016
  • by lucbu
  • Repository
  • 2 Watchers
  • 2 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 50 % Grown

The README.md

Ansible Wrapper Bundle

Introduction

This bundle provide a Wrapper and tools for Ansible 2., (*1)

It can configurate and execute the commands (ansible, ansible-playbook), fire event, reformat error message., (*2)

I'm not an expert, so, please feel free to send pull requests., (*3)

Prerequisite

Installation

Install it with :, (*4)

composer require lucbu/ansible-wrapper-bundle

Add the bundle to kernel :, (*5)

new Lucbu\AnsibleWrapperBundle\LucbuAnsibleWrapperBundle(),

You can create a user that will be used to launch ansible/ansible-playbook command., (*6)

useradd ansible-launcher

Then add the right for your http user to launch command with the user below using visudo (in the sudoers file):, (*7)

www-data ALL=(ansible-launcher) NOPASSWD: /usr/local/bin/ansible
www-data ALL=(ansible-launcher) NOPASSWD: /usr/local/bin/ansible-playbook

You should add this line in ansible.cfg behind "[defaults]", (*8)

stdout_callback = json

Add this in your configuration (config.yml):, (*9)

lucbu_ansible_wrapper:
  ansible:
    user: 'ansible-launcher'    #The user that will launch ansible command
    dir: '/usr/local/bin'       #The folder where is located 'ansible'
  ansible_playbook:
    user: 'ansible-launcher'    #The user that will launch ansible-playbook command
    dir: '/usr/local/bin'       #The folder where is located 'ansible-playbook'

Use

Playbook File (/tmp/ansible/addfile.yml):, (*10)

-
    hosts: all
    tasks:
      - file: path=/tmp/{{ filename }} state=touch mode="u=rw,g=r,o=r"

In the controller:, (*11)

$playbookFile = '/tmp/ansible/addfile.yml';
$vars = ['filename'=>'test'];
$hostFile = '/tmp/hostfile.yml';

$process = AnsiblePlaybookProcessBuilder::createBuilder($playbookFile)
  // Add the vars to command
  ->extraVars($vars)
  // Set the InventoryFile
  ->inventoryFile($hostFile)
  // SSH connecting with user "root"
  ->user('root')
  // Create the process
  ->getAnsiblePlaybookProcess();

$cmd_line = $process->getProcess()->getCommandLine();

try {
    // Executing code (and firing start/new output/finish events)
    $output = $this->container->get('lucbu_ansible_wrapper.ansible_playbook_process_executor')->executeAnsiblePlaybookProcess($process);
} catch (\Exception $e) {
    $output = $e->getMessage();
}

TODO

  • Reformat error message (AnsibleMessageFormatter) (to an object?)
  • Clean the AbstractProcessExecutor?

The Versions

17/11 2016

dev-master

9999999-dev

A Symfony wrapper for Ansible, providing launcher, events...

  Sources   Download

MIT

The Requires

 

by Lucas Burdeyron

wrapper symfony ansible