PHPackages                             asm/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. asm/php-ansible

ActiveLibrary

asm/php-ansible
===============

A PHP wrapper for Ansible.

v6.0.0(2mo ago)214287.0k—0%70[5 issues](https://github.com/maschmann/php-ansible/issues)[3 PRs](https://github.com/maschmann/php-ansible/pulls)MITPHPPHP ^8.2.0|^8.3.0|^8.4.0CI passing

Since May 14Pushed 1mo ago12 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (21)Used By (0)

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

[](#php-ansible-library)

[![Build PHP 8.2/8.3/8.4](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 `ansible-galaxy` commands support both the `role` and `collection` functionality.

#### Role Commands

[](#role-commands)

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 role init my_role --init-path=/tmp/my_path
```

You can access all galaxy role commands:

- `init()`
- `info()`
- `install()`
- `help()`
- `modulelist()`
- `remove()`

#### Collection Commands

[](#collection-commands)

```
$ansible
    ->galaxyCollection()
    ->install('my_namespace.my_collection')
    ->collectionsPath('/tmp/my_path')
    ->execute();
```

would generate:

```
$ ansible-galaxy collection install my_namespace.my_collection --collections-path=/tmp/my_path
```

You can access all galaxy collection commands:

- `init()`
- `build()`
- `publish()`
- `install()`

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)
    …
```

Development
-----------

[](#development)

You can use the provided docker setup with `make build` which creates PHP 8.2, 8.3, and 8.4 containers with modern ansible versions. See the `Dockerfile` and `compose.yaml` for more info. Start the containers with `make up`.
Composer install: `make vendor` (defaults to PHP 8.4, use `make vendor PHP_VERSION=8.2` etc.) You can run code or the tests within the container: `make test`To run tools on a specific PHP version, specify `PHP_VERSION`: `make test PHP_VERSION=8.3`

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

69

—

FairBetter than 100% of packages

Maintenance88

Actively maintained with recent releases

Popularity53

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 50.7% 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.

###  Release Activity

Cadence

Every ~218 days

Recently: every ~365 days

Total

19

Last Release

76d ago

Major Versions

v1.2.0 → v2.0.0-alpha2018-12-15

v2.2.1 → v3.0.12021-06-25

v3.0.1 → v4.0.02022-02-20

v4.1.0 → v5.0.02024-10-01

v5.0.0-rc → v6.0.02026-02-22

PHP version history (9 changes)v0.0.1PHP &gt;=5.4.0

v2.0.0-alphaPHP ^7.2.0

v2.0.0PHP ^7.1.0

2.x-devPHP ^7.1.0|&gt;8.0.0

v3.0.1PHP ^7.3.0|^8.0.0

v4.0.0PHP ^8.0.0

v4.1.0PHP ^8.0.0|^8.1.0|^8.2.0

v5.0.0PHP ^8.1.0|^8.2.0|^8.3.0

v6.0.0PHP ^8.2.0|^8.3.0|^8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ae7274ffaebc203b1541748c0e8c2918b3135bef004ff4c6c8e4d1b6fe1d0f0?d=identicon)[asm](/maintainers/asm)

---

Top Contributors

[![maschmann](https://avatars.githubusercontent.com/u/157620?v=4)](https://github.com/maschmann "maschmann (70 commits)")[![metagusto-opensource](https://avatars.githubusercontent.com/u/17709402?v=4)](https://github.com/metagusto-opensource "metagusto-opensource (34 commits)")[![bambamboole](https://avatars.githubusercontent.com/u/8823695?v=4)](https://github.com/bambamboole "bambamboole (9 commits)")[![acataluddi](https://avatars.githubusercontent.com/u/8874358?v=4)](https://github.com/acataluddi "acataluddi (6 commits)")[![RoussKS](https://avatars.githubusercontent.com/u/7203382?v=4)](https://github.com/RoussKS "RoussKS (6 commits)")[![xabbuh](https://avatars.githubusercontent.com/u/1957048?v=4)](https://github.com/xabbuh "xabbuh (5 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)")[![alxhlz](https://avatars.githubusercontent.com/u/16189604?v=4)](https://github.com/alxhlz "alxhlz (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)")[![GiovanniMet](https://avatars.githubusercontent.com/u/10259446?v=4)](https://github.com/GiovanniMet "GiovanniMet (1 commits)")[![florianbeer](https://avatars.githubusercontent.com/u/800047?v=4)](https://github.com/florianbeer "florianbeer (1 commits)")

---

Tags

ansiblephpphpansible

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M341](/packages/drupal-core-recommended)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)

PHPackages © 2026

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