Skip to content

Instantly share code, notes, and snippets.

@goreilly
Last active September 22, 2016 18:10
Show Gist options
  • Save goreilly/ea93027c058659c5fb233a78ffae2d95 to your computer and use it in GitHub Desktop.
Save goreilly/ea93027c058659c5fb233a78ffae2d95 to your computer and use it in GitHub Desktop.
ansible generate symfony parameters.yml
{
"require": {
"symfony/yaml": "2.2"
}
}
- copy:
remote_src: yes
src: "/var/www/project/app/config/parameters.yml.dist"
dest: "/var/www/project/app/config/parameters.yml"
force: no
owner: '{{ web_user }}'
group: '{{ web_group }}'
mode: 0660
- with_dict: '{{ parameters }}'
lineinfile:
dest: "/var/www/project/app/config/parameters.yml"
line: ' {{ item.key }}: {{ lookup("pipe", role_path ~ "/inline_yaml.php " ~ item.value) }}'
regexp: '^ {{ item.key }}:'
#!/usr/bin/env php
<?php
/**
* This is the same tool symfony uses to convert the parameter file values.
* We can use this so symfony won't change our parameters again after we set them.
*/
use Symfony\Component\Yaml\Inline;
require_once __DIR__.'/../../vendor/autoload.php';
if ($argc !== 2) {
echo 'Usage: inline_yaml.php INPUT';
return 1;
}
$input = $argv[1];
// ansible booleans
switch (strtolower($input)) {
case 'yes':
$input = 'true';
break;
case 'no':
$input = 'false';
break;
}
$value = Inline::parse($input);
if (is_bool($value)) {
$value = $value ? 'true' : 'false';
}
echo $value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment