dev-master
9999999-devA Symfony wrapper for Ansible, providing launcher, events...
MIT
The Requires
by Lucas Burdeyron
wrapper symfony ansible
Wallogit.com
2017 © Pedro Peláez
A Symfony wrapper for Ansible, providing launcher, events...
This bundle provide a Wrapper and tools for Ansible 2., (*1)
It can configurate and execute the commands (ansible, ansible-playbook), fire event, reformat error message., (*2)
I'm not an expert, so, please feel free to send pull requests., (*3)
Install it with :, (*4)
composer require lucbu/ansible-wrapper-bundle
Add the bundle to kernel :, (*5)
new Lucbu\AnsibleWrapperBundle\LucbuAnsibleWrapperBundle(),
You can create a user that will be used to launch ansible/ansible-playbook command., (*6)
useradd ansible-launcher
Then add the right for your http user to launch command with the user below using visudo (in the sudoers file):, (*7)
www-data ALL=(ansible-launcher) NOPASSWD: /usr/local/bin/ansible www-data ALL=(ansible-launcher) NOPASSWD: /usr/local/bin/ansible-playbook
You should add this line in ansible.cfg behind "[defaults]", (*8)
stdout_callback = json
Add this in your configuration (config.yml):, (*9)
lucbu_ansible_wrapper:
ansible:
user: 'ansible-launcher' #The user that will launch ansible command
dir: '/usr/local/bin' #The folder where is located 'ansible'
ansible_playbook:
user: 'ansible-launcher' #The user that will launch ansible-playbook command
dir: '/usr/local/bin' #The folder where is located 'ansible-playbook'
Playbook File (/tmp/ansible/addfile.yml):, (*10)
-
hosts: all
tasks:
- file: path=/tmp/{{ filename }} state=touch mode="u=rw,g=r,o=r"
In the controller:, (*11)
$playbookFile = '/tmp/ansible/addfile.yml';
$vars = ['filename'=>'test'];
$hostFile = '/tmp/hostfile.yml';
$process = AnsiblePlaybookProcessBuilder::createBuilder($playbookFile)
// Add the vars to command
->extraVars($vars)
// Set the InventoryFile
->inventoryFile($hostFile)
// SSH connecting with user "root"
->user('root')
// Create the process
->getAnsiblePlaybookProcess();
$cmd_line = $process->getProcess()->getCommandLine();
try {
// Executing code (and firing start/new output/finish events)
$output = $this->container->get('lucbu_ansible_wrapper.ansible_playbook_process_executor')->executeAnsiblePlaybookProcess($process);
} catch (\Exception $e) {
$output = $e->getMessage();
}
A Symfony wrapper for Ansible, providing launcher, events...
MIT
wrapper symfony ansible