PHPackages                             ibf/php-ansible - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. ibf/php-ansible

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

ibf/php-ansible
===============

A PHP wrapper for Ansible.

13PHP

Since Jan 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/iceberg55/php-ansible)[ Packagist](https://packagist.org/packages/ibf/php-ansible)[ RSS](/packages/ibf-php-ansible/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-ansible library
===================

[](#php-ansible-library)

[![Build PHP 8.0/8.1/8.2](https://github.com/maschmann/php-ansible/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/maschmann/php-ansible/actions/workflows/static-analysis.yml/badge.svg)

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
-------------

[](#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
-----

[](#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

[](#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

[](#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

[](#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-your-contributions)

thank you for reviewing, bug reporting, suggestions and PRs :-) [xabbuh](https://github.com/xabbuh), [emielmolenaar](https://github.com/emielmolenaar), [saverio](https://github.com/saverio), [soupdiver](https://github.com/soupdiver), [linaori](https://github.com/linaori), [paveldanilin](https://github.com/paveldanilin) and many others!

Future features
---------------

[](#future-features)

The Next steps for implementation are:

- improve type handling and structure, due to overall complexity of the playbook at the moment
- scalar typehints all over the place
- provide docker support for development
- move to php8.0 exclusively for the next major release
- wrapping the library into a bundle -&gt; maybe
- provide commandline-capabilities -&gt; maybe

License
-------

[](#license)

php-ansible is licensed under the MIT license. See the [LICENSE](LICENSE) for the full license text.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 51.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2e8b0995d4a03e32c0d19f9f3278e85b94078f9122ad6f130e18e274878e26a9?d=identicon)[iceberg55](/maintainers/iceberg55)

---

Top Contributors

[![maschmann](https://avatars.githubusercontent.com/u/157620?v=4)](https://github.com/maschmann "maschmann (65 commits)")[![metagusto-opensource](https://avatars.githubusercontent.com/u/17709402?v=4)](https://github.com/metagusto-opensource "metagusto-opensource (34 commits)")[![acataluddi](https://avatars.githubusercontent.com/u/8874358?v=4)](https://github.com/acataluddi "acataluddi (6 commits)")[![xabbuh](https://avatars.githubusercontent.com/u/1957048?v=4)](https://github.com/xabbuh "xabbuh (5 commits)")[![bambamboole](https://avatars.githubusercontent.com/u/8823695?v=4)](https://github.com/bambamboole "bambamboole (4 commits)")[![RoussKS](https://avatars.githubusercontent.com/u/7203382?v=4)](https://github.com/RoussKS "RoussKS (4 commits)")[![iceberg55](https://avatars.githubusercontent.com/u/22175435?v=4)](https://github.com/iceberg55 "iceberg55 (1 commits)")[![linaori](https://avatars.githubusercontent.com/u/1754678?v=4)](https://github.com/linaori "linaori (1 commits)")[![emielmolenaar](https://avatars.githubusercontent.com/u/2470795?v=4)](https://github.com/emielmolenaar "emielmolenaar (1 commits)")[![saverio](https://avatars.githubusercontent.com/u/44412?v=4)](https://github.com/saverio "saverio (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![soupdiver](https://avatars.githubusercontent.com/u/800562?v=4)](https://github.com/soupdiver "soupdiver (1 commits)")[![florianbeer](https://avatars.githubusercontent.com/u/800047?v=4)](https://github.com/florianbeer "florianbeer (1 commits)")[![alxhlz](https://avatars.githubusercontent.com/u/16189604?v=4)](https://github.com/alxhlz "alxhlz (1 commits)")[![GiovanniMet](https://avatars.githubusercontent.com/u/10259446?v=4)](https://github.com/GiovanniMet "GiovanniMet (1 commits)")

### Embed Badge

![Health badge](/badges/ibf-php-ansible/health.svg)

```
[![Health](https://phpackages.com/badges/ibf-php-ansible/health.svg)](https://phpackages.com/packages/ibf-php-ansible)
```

###  Alternatives

[deployer/deployer

Deployment Tool

11.1k25.4M207](/packages/deployer-deployer)[appwrite/server-ce

End to end backend server for frontend and mobile apps.

55.3k84.2k](/packages/appwrite-server-ce)[pragmarx/health

Laravel Server &amp; App Health Monitor and Notifier

2.0k1.0M2](/packages/pragmarx-health)[felixfbecker/language-server-protocol

PHP classes for the Language Server Protocol

22476.7M6](/packages/felixfbecker-language-server-protocol)[heroku/heroku-buildpack-php

Toolkit for starting a PHP application locally, with or without foreman, using the same config for PHP and Apache2/Nginx as on Heroku

8161.3M10](/packages/heroku-heroku-buildpack-php)[tiamo/phpas2

PHPAS2 is a php-based implementation of the EDIINT AS2 standard

4674.7k](/packages/tiamo-phpas2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
