Add possibility of prod-specific config.yml file override #455
Comments
How about adding an internal variable to _include_configs:
- config.yml
- local.config.yml Iterating over it in the vconfig = YAML::load_file("#{dir}/provisioning/vars/main.yml")
config_files = vconfig._include_configs
while config_files.length do
config_file = config_files.shift
if File.exist?(config_file)
config = YAML::load_file(config_file) if File.exist?(config_file)
# take into account new config files
config_files.concat config._include_configs if defined? config._include_configs
end
end |
True... but we also need to make sure the configs are set in Ansible itself correctly, and in the prod So we would need support inside the Vagrantfile, but we could then use the new dynamic include functionality in Ansible 2.x to see if the file exists, include it if so, then see if the next one exists, include it if so, etc. Because of that, I'm thinking of waiting until at least 2.0.1 is out, maybe a little further (for more stabilization in 2.x), before making this change. |
Ah, true. |
Taking into account that we need production specific variables like you say, my approach won't do much good. So more brainstorming. Another idea that we discussed somewhere before was ansible In the Vagrantfile we could do add a Downside with this approach is vagrant plugins such as AWS would inherit this |
Sorry I am very new to using drupalvm but needed the ability to do overrides, so ended up editing the Vagrantfile as per below with inspiration from @oxyc. Thought would share for consideration. It is not perfect, a strategy for merge! call requires duplicating for instance apache vhosts otherwise you lose them as last merge wins scenerio. # Use config.yml for basic VM configuration.
require 'yaml'
dir = File.dirname(File.expand_path(__FILE__))
configs = YAML::load_file("#{dir}/provisioning/vars/main.yml")
vconfig = ''
configs['_include_configs'].each do |c|
if File.exist?("#{dir}/#{c}")
conf = YAML::load_file("#{dir}/#{c}") if File.exist?("#{dir}/#{c}")
# take into account new config files
vconfig = conf if vconfig.empty?
vconfig.merge!(conf) if !vconfig.empty?
end
end
# Replace jinja variables in config.
vconfig = walk(vconfig) do |value|
while value.is_a?(String) && value.match(/{{ .* }}/)
value = value.gsub(/{{ (.*?) }}/) { |match| match = vconfig[$1] }
end
value
end |
I'm fine with having to duplicate lists. Without that we wouldn't be able to remove defaults. Unfortunately this doesn't work for direct calls to ansible which is a requirement. It needs to be done in the playbook instead. |
I'm bikeshedding here, but is there a vagrant / ansible standard that would lean towards calling the config files prod.config.yml, local.config.yml, etc? It seems like calling the files config.local.yml, config.prod.yml, etc is more consistent with how I've seen drupal and vagrant operate. |
There's in fact talk of renaming it in core https://www.drupal.org/node/2419213. For me it's just old habits though. |
I like |
Let's punt this to a later time. We now have support for a |
A dirty trick to support a separate production config with #378 is: Create a separate subdirectory with a symlinked Run
|
Issue #455: Allow for environment specific config files
@oxyc's merged fix allows use of a The next step to resolve this is a little extra documentation, maybe in |
Issue #455: Add docs on environment specific configs
This was done by @oxyc's latest commits. Closing the issue out now. Thanks! |
There are still some docs to be taken care of. |
D'oh! |
Issue #455: Move examples/prod readme to docs
@oxyc - Fixed now? Thanks for the help. |
I think so. |
This issue is an offshoot of #84.
Basically, the instructions right now tell you to use one
config.yml
that's modified for production (with more secure variable settings)... but if you do that, then you can't have the sameconfig.yml
be useful for your local development environment in the same Drupal VM instance.It's not the end of the world to have to clone two copies of Drupal VM—one for local, one for prod—but it would be more clean if we could allow some sort of
prod.config.yml
, using the same kind of idea @oxyc mentioned elsewhere about having alocal.config.yml
override.So the hierarchy of config files would be
prod.config.yml
>local.config.yml
>config.yml
. Something like that. I haven't quite worked out the specifics, and maybe there's a better way to do this architecturally, but I wanted to split this issue off of #84 so I could at least get that completed.The text was updated successfully, but these errors were encountered: