All Projects → maschmann → Php Ansible

maschmann / Php Ansible

Licence: mit
php oop wrapper for ansible provisioning tool

Labels

Projects that are alternatives of or similar to Php Ansible

Ansible Role K3s
Ansible role for installing k3s as either a standalone server or HA cluster.
Stars: ✭ 132 (-10.2%)
Mutual labels:  ansible
Tensor
Tensor - Comprehensive web-based automation framework and Centralized infrastructure management platform
Stars: ✭ 136 (-7.48%)
Mutual labels:  ansible
Forklift
Helpful deployment scripts for Foreman and Katello
Stars: ✭ 141 (-4.08%)
Mutual labels:  ansible
Ansible Filter Plugins
Documentation of all ansible filters and some custom ones
Stars: ✭ 133 (-9.52%)
Mutual labels:  ansible
Cygwin Portable Installer
Windows batch file to perform unattended installations of a portable Cygwin environment.
Stars: ✭ 135 (-8.16%)
Mutual labels:  ansible
Td4a
Template designer for automation
Stars: ✭ 139 (-5.44%)
Mutual labels:  ansible
Ansible Human log
This Ansible callback plugin for human-readable result logging for Ansible 1.9/2.0-2.4.
Stars: ✭ 132 (-10.2%)
Mutual labels:  ansible
Oracle Java
Ansible role to install Oracle Java 8/11 on Debian and RedHat based distributions.
Stars: ✭ 144 (-2.04%)
Mutual labels:  ansible
Network
An ansible role to configure networking
Stars: ✭ 134 (-8.84%)
Mutual labels:  ansible
Ansible Role Nfs
Ansible Role - NFS
Stars: ✭ 141 (-4.08%)
Mutual labels:  ansible
Ansible Role Dotfiles
Ansible Role - Easy and flexible dotfile installation.
Stars: ✭ 133 (-9.52%)
Mutual labels:  ansible
Ypsilon
Automated Use Case Testing
Stars: ✭ 135 (-8.16%)
Mutual labels:  ansible
Redfish Ansible Module
Ansible modules for Out-Of-Band Controllers using Redfish APIs
Stars: ✭ 139 (-5.44%)
Mutual labels:  ansible
Ansible Dev By Example
💥 Ansible module development with examples and walk-throughs
Stars: ✭ 133 (-9.52%)
Mutual labels:  ansible
Ansibleplaybooks
A collection of Ansible Playbooks that configure Kali to use Fish & install a number of tools
Stars: ✭ 143 (-2.72%)
Mutual labels:  ansible
Ansible Mysql Hardening
This Ansible role provides security configuration for MySQL.
Stars: ✭ 132 (-10.2%)
Mutual labels:  ansible
Ansible Role Logstash
Ansible Role - Logstash
Stars: ✭ 136 (-7.48%)
Mutual labels:  ansible
Gitlab Ci Stack
Full CI pipeline project based on Gitlab & Gitlab CI running Docker, completely automated setup by Vagrant & Ansible, providing Let´s Encrypt certificates for private Servers, multiple Gitlab-Runners and the Gitlab Container Registry, incl. GitLab Pages
Stars: ✭ 146 (-0.68%)
Mutual labels:  ansible
Ansible Gitlab Runner
Ansible role to install gitlab-runner
Stars: ✭ 143 (-2.72%)
Mutual labels:  ansible
Ansible stdout compact logger
Ansible Stdout Compact Logger
Stars: ✭ 141 (-4.08%)
Mutual labels:  ansible

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 the ansible-playbook and ansible-galaxy commands.

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.

$ansible = new Ansible(
    '/path/to/ansible/deployment'
);

Optionally, you can specify the path of your ansible-playbook and ansible-galaxy commands, just in case they are not in the PATH.

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

You can also pass any PSR compliant logging class to have further details logged. This is especially useful to have the actual run command logged.

$ansible = new Ansible(
    '/path/to/ansible/deployment'
);

// $logger is a PSR-compliant logging implementation (e.g. monolog)
$ansible->setLogger($logger);

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.

You can also pass an external YML/JSON file as extraVars containing a complex data structure to be passed to Ansible:

$ansible
    ->playbook()
    ->play('mydeployment.yml') // based on deployment root 
    ->extraVars('/path/to/your/extra/vars/file.yml')
    ->execute();

You can have a Json output adding json() option that enable 'ANSIBLE_STDOUT_CALLBACK=json' env vars to make a json output in ansible.

$ansible
    ->playbook()
    ->json()
    ->play('mydeployment.yml') // based on deployment root 
    ->extraVars('/path/to/your/extra/vars/file.yml')
    ->execute();

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()
  • 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)
    

Thank you for your contributions!

thank you for reviewing, bug reporting, suggestions and PRs :-) xabbuh, emielmolenaar, saverio, soupdiver, linaori, paveldanilin

Future features

The Next steps for implementation are:

  • wrapping the library into a bundle.
  • provide commandline-capabilities.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].