Skip to content

global_configs - Delay evaluation until converge phase #68

@webframp

Description

@webframp

Hi there! Thanks for this cookbook.

I ran into a fun issue due to the delightful multi-phase execution model of chef figured I'd report it. I did find a workaround, but it's just slightly ugly.

The root issue is this spot in the global_configs recipe which is troublesome with a custom user: https://github.com/djoos-cookbooks/composer/blob/master/recipes/global_configs.rb#L12

When node['composer']['global_configs'] contains a user that does not yet exist, but will be created during the chef recipe, then composer::global_configs will fail with something like this beautiful message:

       ================================================================================
       Recipe Compile Error in /tmp/kitchen/cache/cookbooks/bethel_packaging/recipes/default.rb
       ================================================================================

       ArgumentError
       -------------
       user satis doesn't exist

       Cookbook Trace:
       ---------------
         /tmp/kitchen/cache/cookbooks/composer/recipes/global_configs.rb:12:in `home'
         /tmp/kitchen/cache/cookbooks/composer/recipes/global_configs.rb:12:in `block in from_file'
         /tmp/kitchen/cache/cookbooks/composer/recipes/global_configs.rb:11:in `each_pair'
         /tmp/kitchen/cache/cookbooks/composer/recipes/global_configs.rb:11:in `from_file'
         /tmp/kitchen/cache/cookbooks/composer/recipes/default.rb:11:in `from_file'
         /tmp/kitchen/cache/cookbooks/bethel_packaging/recipes/satis.rb:16:in `from_file'
         /tmp/kitchen/cache/cookbooks/bethel_packaging/recipes/default.rb:9:in `from_file'

       Relevant File Content:
       ----------------------
       /tmp/kitchen/cache/cookbooks/composer/recipes/global_configs.rb:

         5:  # Copyright (c) 2016, David Joos
         6:  #
         7:
         8:  configs = node['composer']['global_configs']
         9:
        10:  unless configs.nil?
        11:    configs.each_pair do |user, user_configs|
        12>>     user_composer_dir = "#{Dir.home(user)}/.composer"
        13:
        14:      directory user_composer_dir do
        15:        owner user
        16:        group user
        17:        mode 0755
        18:        action :create
        19:      end
        20:
        21:      user_configs.nil? && next

       Platform:
       ---------
       x86_64-linux

yuck ^

The workaround is to make your user resource (wherever it is) run during the compile phase and it looks like this:

user satis_user do
  comment 'local user for satis'
  manage_home true
  action :nothing
end.run_action(:create)

With that little method tagged onto the end of the resource it worked as intended I think. So it may be useful to do one of:

  1. Make a note in the README of this behavior
  2. Rework global_configs in some way to use a lazy eval style so it only runs during the converge phase

Hope this info is helpful in some way.

Metadata

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