{"id":13715538,"url":"https://github.com/maschmann/php-ansible","last_synced_at":"2026-02-21T21:09:38.259Z","repository":{"id":31909633,"uuid":"35478762","full_name":"maschmann/php-ansible","owner":"maschmann","description":"php oop wrapper for ansible provisioning tool","archived":false,"fork":false,"pushed_at":"2024-10-02T07:12:01.000Z","size":161,"stargazers_count":211,"open_issues_count":8,"forks_count":70,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-12-17T14:35:42.015Z","etag":null,"topics":["ansible","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maschmann.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-12T09:21:24.000Z","updated_at":"2025-09-10T16:23:49.000Z","dependencies_parsed_at":"2024-11-29T23:00:17.097Z","dependency_job_id":null,"html_url":"https://github.com/maschmann/php-ansible","commit_stats":{"total_commits":90,"total_committers":18,"mean_commits":5.0,"dds":0.6333333333333333,"last_synced_commit":"8d03a841907c20c5afa7ed2ac9f5ef30586f9bc2"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/maschmann/php-ansible","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maschmann%2Fphp-ansible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maschmann%2Fphp-ansible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maschmann%2Fphp-ansible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maschmann%2Fphp-ansible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maschmann","download_url":"https://codeload.github.com/maschmann/php-ansible/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maschmann%2Fphp-ansible/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29694198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T18:18:25.093Z","status":"ssl_error","status_checked_at":"2026-02-21T18:18:22.435Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","php"],"created_at":"2024-08-03T00:01:00.269Z","updated_at":"2026-02-21T21:09:38.238Z","avatar_url":"https://github.com/maschmann.png","language":"PHP","readme":"# php-ansible library\n![Build PHP 8.0/8.1/8.2](https://github.com/maschmann/php-ansible/actions/workflows/static-analysis.yml/badge.svg)\n\nThis library is a OOP-wrapper for the ansible provisioning tool.\nI intend to use this library for a symfony2 bundle and also a deployment GUI, based on php/symfony2.\nThe current implementation is feature-complete for the `ansible-playbook` and `ansible-galaxy` commands.\n\n\n\n## Prerequisites\n\nYour OS should be a flavor of linux and ansible has to be installed. It's easiest if ansible is in PATH :-)\nThe library tries to find ansible-playbook and ansible-galaxy by itself or use the paths/executables you provide. \n\n\n## Usage\n\nFirst instantiate the base object which works as a factory for the commands.\nOnly the first parameter is mandatory, and provides the library with the path to your ansible deployment file structure. \n\n```php\n$ansible = new Ansible(\n    '/path/to/ansible/deployment'\n);\n```\n\nOptionally, you can specify the path of your `ansible-playbook` and `ansible-galaxy` commands, just in case they are not in the PATH.\n\n```php\n$ansible = new Ansible(\n    '/path/to/ansible/deployment',\n    '/optional/path/to/command/ansible-playbook',\n    '/optional/path/to/command/ansible-galaxy'\n);\n```\n\nYou can also pass any PSR compliant logging class to have further details logged. This is **especially useful to have the actual run command logged**.\n\n```php\n$ansible = new Ansible(\n    '/path/to/ansible/deployment'\n);\n\n// $logger is a PSR-compliant logging implementation (e.g. monolog)\n$ansible-\u003esetLogger($logger);\n```\n\n\n\n### Playbooks\n\nThen you can use the object just like in your previous ansible deployment.\nIf you don't specify an inventory file with ```-\u003einventoryFile('filename')```, the wrapper tries to determine one, based on your playbook name: \n\n```php\n$ansible\n    -\u003eplaybook()\n    -\u003eplay('mydeployment.yml') // based on deployment root \n    -\u003euser('maschmann')\n    -\u003eextraVars(['project_release' =\u003e 20150514092022])\n    -\u003elimit('test')\n    -\u003eexecute();\n```\n\nThis will create following ansible command:\n\n```bash\n$ ansible-playbook mydeployment.yml -i mydeployment --user=maschmann --extra-vars=\"project-release=20150514092022\" --limit=test\n```\n\n\nFor the execute command you can use a callback to get real-time output of the command:\n\n```php\n$ansible\n    -\u003eplaybook()\n    -\u003eplay('mydeployment.yml') // based on deployment root \n    -\u003euser('maschmann')\n    -\u003eextraVars(['project_release' =\u003e 20150514092022])\n    -\u003elimit('test')\n    -\u003eexecute(function ($type, $buffer) {\n        if (Process::ERR === $type) {\n            echo 'ERR \u003e '.$buffer;\n        } else {\n            echo 'OUT \u003e '.$buffer;\n        }\n    });\n```\nIf 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.\n\nYou can also pass an external YML/JSON file as extraVars containing a complex data structure to be passed to Ansible:\n\n```php\n$ansible\n    -\u003eplaybook()\n    -\u003eplay('mydeployment.yml') // based on deployment root \n    -\u003eextraVars('/path/to/your/extra/vars/file.yml')\n    -\u003eexecute();\n```\n\nYou can have a Json output adding json() option that enable 'ANSIBLE_STDOUT_CALLBACK=json' env vars to make a json output in ansible.\n\n```php\n$ansible\n    -\u003eplaybook()\n    -\u003ejson()\n    -\u003eplay('mydeployment.yml') // based on deployment root \n    -\u003eextraVars('/path/to/your/extra/vars/file.yml')\n    -\u003eexecute();\n```\n\n### Galaxy\n\nThe syntax follows ansible's syntax with one deviation: list is a reserved keyword in php (array context) and\ntherefore I had to rename it to \"modulelist()\".\n\n```php\n$ansible\n    -\u003egalaxy()\n    -\u003einit('my_role')\n    -\u003einitPath('/tmp/my_path') // or default ansible roles path\n    -\u003eexecute();\n```\nwould generate:\n\n```bash\n$ ansible-galaxy init my_role --init-path=/tmp/my_path\n```\n\nYou can access all galaxy commands:\n\n * `init()`\n * `info()`\n * `install()`\n * `help()`\n * `modulelist()`\n * `remove()`\n\nYou 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().\n\nPossible arguments/options:\n\n * `initPath()`\n * `offline()`\n * `server()`\n * `force()`\n * `roleFile()`\n * `rolesPath()`\n * `ignoreErrors()`\n * `noDeps()`\n\n\n\n### Process timeout\n\nDefault process timeout is set to 300 seconds. If you need more time to execute your processes: Adjust the timeout :-) \n\n```php\n$ansible\n    -\u003egalaxy()\n    -\u003esetTimeout(600)\n    …\n```\n\n## Development\n\nYou can use the provided docker image with ```make build``` which uses a default php-cli docker image and ansible 2.x. See the ```Dockerfile``` for more info.  \nStart the container with ```make up```.  \nComposer install: ```make vendor```  \nYou can run code or the tests within the container: ```make test c=\"--testdox\"```\n\n## Thank you for your contributions!\n\nthank you for reviewing, bug reporting, suggestions and PRs :-)\n[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! \n\n\n\n## Future features\n\nThe Next steps for implementation are:\n\n- improve type handling and structure, due to overall complexity of the playbook at the moment\n- scalar typehints all over the place\n- provide docker support for development\n- wrapping the library into a bundle -\u003e maybe\n- provide commandline-capabilities -\u003e maybe\n\n\n\nLicense\n----\n\nphp-ansible is licensed under the MIT license. See the [LICENSE](LICENSE) for the full license text.\n","funding_links":[],"categories":["Tools","php"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaschmann%2Fphp-ansible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaschmann%2Fphp-ansible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaschmann%2Fphp-ansible/lists"}