Code Monkey home page Code Monkey logo

php-ansible's Introduction

php-ansible library

Build Status Scrutinizer Code Quality Code Coverage

This library is a oop-wrapper for the ansible provisioning tool. I intend to use this library for a symfony2 bundle and also a deployment GUI, based on php/symfony2. The current implementation is feature-complete for ansible-playbook and ansible-galaxy

Next steps for implementation are: wrapping the lib into a bundle and provide e.g. commandline-capabilities.

prerequisites

Your OS should be a flavor of linux and ansible has to be installed. It's easiest if ansible is in PATH :-) The library tries to find ansible-playbook and ansible-galaxy by itself or use the paths/executables you provide.

usage

First instantiate the base object which works as a factory for the commands. Only the first parameter is mandatory, and provides the library with the path to your ansible deployment file structure. The other two params are optional paths to your local ansible installation's binaries, in case they are not in PATH.

    $ansible = new Ansible(
        '/path/to/ansible/deployment',
        '/optional/path/to/ansible-playbook',
        '/optional/path/to/ansible-galaxy'
    );

playbooks

Then you can use the object just like in your previous ansible deployment. If you don't specify an inventory file with ->inventoryFile('filename'), the wrapper tries to determine one, based on your playbook name:

    $ansible
        ->playbook()
        ->play('mydeployment.yml') // based on deployment root 
        ->user('maschmann')
        ->extraVars(['project_release=20150514092022'])
        ->limit('test')
        ->execute();

This will create following ansible command:

$ ansible-playbook mydeployment.yml -i mydeployment --user=maschmann --extra-vars="project-release=20150514092022" --limit=test

For the execute command you can use a callback to get real-time output of the command:

    $ansible
        ->playbook()
        ->play('mydeployment.yml') // based on deployment root 
        ->user('maschmann')
        ->extraVars(['project_release=20150514092022'])
        ->limit('test')
        ->execute(function ($type, $buffer) {
            if (Process::ERR === $type) {
                echo 'ERR > '.$buffer;
            } else {
                echo 'OUT > '.$buffer;
            }
        });

If no callback is given, the method will return the ansible-playbook output as a string, so you can either echo or directly pipe it into a log/whatever.

galaxy

The syntax follows ansible's syntax with one deviation: list is a reserved keyword in php (array context) and therefore I had to rename it to "modulelist()".

    $ansible
        ->galaxy()
        ->init('my_role')
        ->initPath('/tmp/my_path') // or default ansible roles path
        ->execute();

would generate:

$ ansible-galaxy init my_role --init-path=/tmp/my_path

You can access all galaxy commands:

  • init()
  • info()
  • install()
  • help()
  • modulelist() //list
  • remove()

You can combine the calls with their possible arguments, though I don't have any logic preventing e.g. --force from being applied to e.g. info().

Possible arguments/options:

  • initPath()
  • offline()
  • server()
  • force()
  • roleFile()
  • rolesPath()
  • ignoreErrors()
  • noDeps()

process timeout

Default process timeout is set to 300 seconds. If you need more time to execute your processes: Adjust the timeout :-)

    $ansible
        ->galaxy()
        ->setTimeout(600)
        ...

license

php-ansible is licensed under the MIT license. See the LICENSE for the full license text.

php-ansible's People

Contributors

emielmolenaar avatar linaori avatar maschmann avatar saverio avatar scrutinizer-auto-fixer avatar soupdiver avatar xabbuh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.