Replace configuration line with Ansible

Asked

Viewed 489 times

0

Filing cabinet:

<?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);

Rather than:

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

Main file.yml:

I’m trying to do this, but it doesn’t 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": ""}
  • The estate dest of replace is not documented. Are you sure it’s dest and not path?

  • 1

    We found another solution @Andersoncarloswoss

2 answers

1

You can also use the lineinfile module this way:

- name:  Change to Symfony development enviroment for reflect the changes directly on the vagrant box
  lineinfile:
    path: /etc/selinux/config
    regexp: '^\$kernel = new AppKernel('prod', false);'
    line: '$kernel = new AppKernel('dev', true);'

References
Ansible Documentation for lineinfile module

  • This is the second time you’ve asked for an edit to modify the scope of someone else’s answer. When so put your considerations as comment or ask license to the operator who gave the answer to modify the proposed content. Either make the considerations in your own answer or add a new answer to the question.

  • 1

    Sorry. As I have no points to comment I chose to edit the answer to complete with more information. :(

  • Sometimes we have to put ourselves in the position of the other operator, for example I liked your answer so I sent +1 but imagine that I did not like it and used my editing power to change the content of your answer that you believe is correct for something else that you did not intend. You’d probably be pissed you had to undo the changes. The page encourages edits but don’t change or add content just make it easy for the response to be visually better received.

  • 1

    I noticed and chose to make an answer. Thanks for +1 and you’re absolutely right.

0

Worked that 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 in regexp:

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

References

Stackoverflow - Replace Configuration line with Ansible

Browser other questions tagged

You are not signed in. Login or sign up in order to post.