Chef 13 Upgrade: Rubocop Changes for lazy Parameters

As part of an upgrade from Chef 12 to Chef 13, this is one of the posts in which I've been detailing the issues I've encountered, and how I've resolved them .

When running Rubocop from ChefDK 2 against the following code, we receive the error Parenthesize the param lazy { ... } to make sure that the block will be associated with the lazy method call twice:

template 'Chef deploy user\'s authorized_keys' do
  source 'authorized_keys.erb'
  path lazy { "#{node['etc']['passwd']['chef']['dir']}/.ssh/authorized_keys" }
  user 'chef'
  group 'chef'
  mode '0600'
  variables lazy {
    {
      public_keys: node['authorized_keys'] + [node.run_state['public_key/deploy']]
    }
  }
end

This error can be resolved by adding a parentheses around the whole lazy { } blocks:

 template 'Chef deploy user\'s authorized_keys' do
   source 'authorized_keys.erb'
-  path lazy { "#{node['etc']['passwd']['chef']['dir']}/.ssh/authorized_keys" }
+  path(lazy { "#{node['etc']['passwd']['chef']['dir']}/.ssh/authorized_keys" })
   user 'chef'
   group 'chef'
   mode '0600'
-  variables lazy {
+  variables(lazy do
     {
       public_keys: node['authorized_keys'] + [node.run_state['public_key/deploy']]
     }
-  }
+  end)
 end

Note that I've also converted the multi-line block to a do / end block, as that was another complaint of Rubocop.

Written by Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

Categories
Tags
Related Posts

Other posts you may be interested in:

Interactions with this post

Interactions with this post

This post has had 0 WebMention interactions, as of Thu, 23 May 2019 13:53:36 +0100.

Have you written a response to this post? Let me know the URL: