Has this idea been explored?

I have started writing a set of PHP classes to be located 
here https://github.com/Appdynamics/ansible-php. The idea is to, as part of 
the task, if the module is determined to be written in PHP (check shebang), 
then copy this library over to the right place. The PHP process would be 
called with a custom INI file that would have include_path set properly. 
The module then only needs a short amount of code to start with just like a 
Python-based Ansible module. The primary use case would be with websites 
written in PHP that need easier interfacing than using Python. Typical site 
types include Drupal, WordPress, and sites written with the Syfmony 2 
framework. While all of these have command line helpers (drush and wp-cli, 
Symfony 2 console), it is quite useless to have 'changed: true' every time 
you run a command (via command or shell modules) when nothing has really 
changed.

Example module (the only boilerplate is the first 3 lines):

#!/usr/bin/env php
<?php
require 'Ansible.php'; // class auto-loading file or just includes all of 
them

$module = new AnsibleModule(
    array('dir' => array('type' => 'directory'), 'set_mode' => array('type' 
=> 'bool'), 'mode' => array('choices' => array('production', 'staging', 
'dev'))
);
$include = $module->params['dir'] . DIRECTORY_SEPARATOR . 'somecode.inc';
$should_set_mode = $module->params['set_mode']; // === true or false, 
because of the type key in the argument specification
$target_mode = $module->params['mode'];

$changed = false;

// Here, require the PHP code at the $dir argument, and set the application 
to the mode if $should_set_mode === true
// If an error occurs, call $module->failJson(); optionally with an array 
of data

$module->exitJson(array('changed' => $changed));

One area of concern is compatibility, so I am avoiding using new features 
such as namespaces. Perhaps the oldest version to go down to is PHP 5.2 
(influenced mostly by CodeIgniter's standards).

If this were to be seriously explored and merged into Ansible core, I would 
like to know where these files would go. The lib/ directory seems the most 
likely place.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9760a8c8-eb80-4b5e-8e5c-70bfa7b0899c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to