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

How to hardcode includes #8

Open
mjallday opened this issue Jan 9, 2014 · 3 comments
Open

How to hardcode includes #8

mjallday opened this issue Jan 9, 2014 · 3 comments
Labels

Comments

@mjallday
Copy link
Contributor

mjallday commented Jan 9, 2014

how does chef know how to include templates?

if i change this line https://github.com/balanced-cookbooks/balanced-ci/blob/new-jobs/libraries/balanced_ci_job.rb#L16

to source 'job-balanced.xml.erb'

i get the error


Chef::Exceptions::FileNotFound
------------------------------
balanced_ci_job[balanced-test] (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/balanced-ci/libraries/balanced_ci_pipeline.rb line 65) had an error: Chef::Exceptions::FileNotFound: jenkins_job[balanced-test] (/tmp/
vagrant-chef-1/chef-solo-1/cookbooks/balanced-ci/libraries/balanced_ci_job.rb line 15) had an error: Chef::Exceptions::FileNotFound: template[/var/lib/jenkins/jobs/balanced-test/config.xml] (/tmp/vagrant-chef
-1/chef-solo-1/cookbooks/jenkins/libraries/jenkins_job.rb line 77) had an error: Chef::Exceptions::FileNotFound: Cookbook 'ci' (1.0.12) does not contain a file at any of these locations:
  templates/ubuntu-12.04/job-balanced.xml.erb
  templates/ubuntu/job-balanced.xml.erb
  templates/default/job-balanced.xml.erb

This cookbook _does_ contain: ['/tmp/vagrant-chef-1/chef-solo-1/cookbooks/ci/templates/default/git.xml.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/ci/templates/default/google_auth.xml.erb','/tmp/vagrant-c
hef-1/chef-solo-1/cookbooks/ci/templates/default/job-config.xml.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/ci/templates/default/slave_user.xml.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/ci/templates
/default/ssh_config.erb']

@coderanger
Copy link
Contributor

I think this was resolved with the template_content changes?

@coderanger
Copy link
Contributor

Ahh okay, I see what you were referencing. Time for an infodump:

So to render a template, Chef needs two bits of information: the template name and which cookbook the template is in (hereafter template source and template cookbook). For the template source, you either have to pass that when you create the resource instance, or optionally give a default_source when defining the resource. For the template cookbook you have four options (checked in order):

  1. Pass an explicit cookbook when creating the resource.
  2. If an explicit source in the resource, it will use the cookbook the resource was instantiated in.
  3. If given when the resource was defined, default_cookbook is used.
  4. Magic fallback: if none of the above cases triggered, poise tries to figure out what cookbook the resource was defined in.

Most of the time we want to be using case 4, but there is a hitch. What 4 is actually computing is the cookbook of the thing that called attribute('', template: true, ...). This means that when you subclass ci_job, it was still looking for templates in the ci cookbook even though the new class is in balanced-ci.

So how do we fix this? I just pushed a change to poise that should provide flexible enough semantics. In short the change is that if you define the same template_content attribute again in a subclass, it inherits the options from the original. This means that in balanced_ci_job you can just add attribute('', template:true) and that will leave the default_source and default_options from the base class intact, but reset the cookbook detected in case 4.

This has been a 2AM braindump. We now return you to your regularly scheduled programming.

@mahmoudimus
Copy link
Contributor

@coderanger this is no longer an issue given https://github.com/balanced-cookbooks/jenkins/pull/2 rght?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants