Skip to content

redis config file should be updated as needed (desired state) #478

Open
@nicksma

Description

The guard allows to set the redis configuration in the first run. Once the breadcrumb is written along with the configuration file, the config is never getting updated anymore. This is the case even while changing the address, the maxclients or any other parameter configurable by this provider.

not_if { ::File.exist?("#{current['configdir']}/#{server_name}.conf.breadcrumb") }

Solution could be, instead of defining the variables attributes inside the resource, we will fill a variable variables_to_be_set with these information. This variable will be used in the template resource later.
To check, if these variables have changed, we generate a hash and store the value in the breadcrumb file. With these information we are able to guard the template resource by checking if the breadcrumb file contains the fresh calculated hash. If not, we have to execute the template resource, which will write the changed configuration file.
In this case we need to update the breadcrumb file with the new hash, done by the file resource with the modified content and the action changed to create.

This is just a snippets to show the idea and needs to be fleshed out:

    variables_to_be_set = variables( 
      version: version_hash, 
      piddir: piddir, 
      ...
      repldisklesssync:           current['repldisklesssync'],
      repldisklesssyncdelay:      current['repldisklesssyncdelay'] 
    )

    config_hash = hash(variables_to_be_set)

    # Lay down the configuration files for the current instance
    template "#{current['configdir']}/#{server_name}.conf" do
      source node['redisio']['redis_config']['template_source']
      cookbook node['redisio']['redis_config']['template_cookbook']
      owner current['user']
      group current['group']
      mode current['permissions']
      action :create
      variables variables_to_be_set
      not_if { ::File.foreach("#{current['configdir']}/#{server_name}.conf.breadcrumb").grep(#{config_hash}).any? }}
    end

    file "#{current['configdir']}/#{server_name}.conf.breadcrumb" do
      content 'This file prevents the chef cookbook from overwriting the redis config if config has not changed. \nconfig_hash: #{config_hash}'
      action :create
      only_if { current['breadcrumb'] == true }
    end

Thank you for your excellent code and for maintaining it. :)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions