Replace configuration line with Ansible

0

File:

<?php

use Symfony\Component\HttpFoundation\Request;

/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../vendor/autoload.php';
if (PHP_VERSION_ID < 70000) {
    include_once __DIR__.'/../var/bootstrap.php.cache';
}

$kernel = new AppKernel('prod', false);
if (PHP_VERSION_ID < 70000) {
    $kernel->loadClassCache();
}
//$kernel = new AppCache($kernel);

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

Description:

I want to replace the line with the following content:

$kernel = new AppKernel('dev', true);

Instead of:

$kernel = new AppKernel('prod', false);

Main.yml file:

I'm trying to do this, but it does not work:

- name: Change to Symfony development enviroment for reflect the changes directly on the vagrant box
  replace: dest=/vagrant/symfony-standard/web/app.php regexp='$kernel = new AppKernel('prod', false);' replace='$kernel = new AppKernel('dev', true);' backup=yes

Terminal:

TASK [symfony-standard : Change to Symfony development enviroment for reflect the changes directly on the vagrant box] ***
task path: /vagrant/playbooks/roles/symfony-standard/tasks/main.yml:49
ok: [default] => {"changed": false, "msg": ""}
    
asked by anonymous 06.05.2017 / 22:42

1 answer

0

It worked this way:

- name:  Change to Symfony development enviroment for reflect the changes directly on the vagrant box
  replace:
    dest: /vagrant/symfony-standard/web/app.php
    regexp: \$kernel = new.*$
    replace: $kernel = new AppKernel('dev', true);

And also adding this excerpt to regexp :

\$kernel = new AppKernel\('prod', false\);

References

Stackoverflow - Replace configuration line with Ansible

    
07.05.2017 / 23:46