Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Resource throwing error when using variable for name #477

Closed
TheSerapher opened this issue Aug 7, 2014 · 6 comments
Closed

Template Resource throwing error when using variable for name #477

TheSerapher opened this issue Aug 7, 2014 · 6 comments

Comments

@TheSerapher
Copy link

I have the following part in my recipe:

# rubocop:disable Style/LineLength,
{ 'vsftpd.conf.erb' => config,
  'vsftpd.chroot_list.erb' => node['vsftpd']['config']['chroot_list_file'],
  'vsftpd.user_list.erb' => node['vsftpd']['config']['userlist_file'] }.each do |template, destination|
  # rubocop:enable Style/LineLength
  template destination do
    source template
    notifies :restart, 'service[vsftpd]', :delayed
  end
end

This works fine when running Chef but after removing an old Gemfile.lock and re-running bundler, my tests are now failing with the following error:

  1) vsftpd::default for redhat should install vsftpd
     Failure/Error: @chef_run.converge(described_recipe)
     ArgumentError:
       You must supply a name when declaring a template resource
     # /var/folders/cq/nq8c5w4d4ns_r_4tg_s2nzqh0000gn/T/d20140807-14278-1rr9z71/cookbooks/vsftpd/recipes/_configure.rb:26:in `block in from_file'
     # /var/folders/cq/nq8c5w4d4ns_r_4tg_s2nzqh0000gn/T/d20140807-14278-1rr9z71/cookbooks/vsftpd/recipes/_configure.rb:24:in `each'
     # /var/folders/cq/nq8c5w4d4ns_r_4tg_s2nzqh0000gn/T/d20140807-14278-1rr9z71/cookbooks/vsftpd/recipes/_configure.rb:24:in `from_file'
     # /var/folders/cq/nq8c5w4d4ns_r_4tg_s2nzqh0000gn/T/d20140807-14278-1rr9z71/cookbooks/vsftpd/recipes/default.rb:4:in `from_file'
     # ./spec/default_spec.rb:13:in `block (4 levels) in <top (required)>'

The Cookbook in question can be downloaded here, removing the Gemfile.lock and re-running bundler will show the error: https://github.com/TheSerapher/chef-vsftpd

If you need more details let me know.

@TheSerapher
Copy link
Author

Here some output from running bundler install on the existing gems upgrading those that were added after removing the Gemfile.lock. I left those out that didn't change.

Installing buff-config 1.0.1
Installing hitimes 1.2.2
Installing timers 4.0.0
Installing celluloid 0.16.0.pre3
Installing celluloid-io 0.16.0.pre2
Installing octokit 3.3.0
Installing semverse 1.2.1
Installing dep-selector-libgecode 1.0.2
Installing solve 1.2.1
Installing berkshelf 3.1.5
Installing chef-zero 2.2
Installing libyajl2 1.0.1
Installing ffi-yajl 1.0.1
Installing systemu 2.6.4
Installing wmi-lite 1.0.0
Installing ohai 7.2.0
Installing slop 3.6.0
Installing chef 11.14.2
Installing fauxhai 2.2.0
Installing rspec-support 3.0.3
Installing rspec-core 3.0.3
Installing rspec-expectations 3.0.3
Installing rspec-mocks 3.0.3
Installing chefspec 4.0.1
Installing nokogiri 1.6.3.1
Installing parser 2.2.0.pre.3
Installing rubocop 0.24.1

I guess it could be caused by rspec upgrades too? In any case, it used to work before.

@TheSerapher
Copy link
Author

Nerver mind, followed the wrong trail. I will keep looking but I am not sure what's causing this.

Removing the comments to avoid confusion.

@sethvargo
Copy link
Contributor

Hey @TheSerapher. I think I see your problem, but it's hard to be certain without a bit more information.

You have a hash like this:

{
  'vsftpd.conf.erb' => config,
  'vsftpd.chroot_list.erb' => node['vsftpd']['config']['chroot_list_file'],
  'vsftpd.user_list.erb' => node['vsftpd']['config']['userlist_file']
}

And then you iterate over that key-value map like this:

.each do |template, destination|

And then you call:

template destination

But, if any one of those values in the hash are nil, for example:

{
  'vsftpd.conf.erb' => config,
  'vsftpd.chroot_list.erb' => nil,
  'vsftpd.user_list.erb' => node['vsftpd']['config']['userlist_file']
}

You're calling:

template nil

I think the fact it is breaking with the Gemfile.lock is a redherring. Can you inspect the values of those node attributes and config before the hash in your recipe and make sure they have values?

@TheSerapher
Copy link
Author

You are spot on. And it's caused by Fauxhai :-)

I do this before:

config = value_for_platform_family(
  'rhel' => '/etc/vsftpd/vsftpd.conf',
  'redhat' => '/etc/vsftpd/vsftpd.conf',
  'centos' => '/etc/vsftpd/vsftpd.conf',
  'debian' => '/etc/vsftpd.conf'
)

Somehow one of them seems to be empty when upgrading from Fauxhai 2.1.2 to 2.2.0. I will dig deeper and fix locally, I doubt it's your issue!

@sethvargo
Copy link
Contributor

@TheSerapher if it's fauxhai, it's my issue 😄. I own that project too. If you're able to track it down, would you mind opening an issue on the fauxhai repo please?

@TheSerapher
Copy link
Author

Done: chefspec/fauxhai#114

@lock lock bot locked as resolved and limited conversation to collaborators Aug 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants