Running a hostfile cookbook on OpsWorks


I’m trying to run a cookbook called hostsfile on Opsworks and get the following error in the log:

17: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: # See the License for the specific language governing permissions and
19: # limitations under the License.
20: #
22: default[‘hostsfile’][‘path’] = nil
24>> hostsfile_entry ‘x.x.x.x’ do
25: hostname 'blah.blah’
26: aliases 'blah’
27: action :create_if_missing
28: end
30: hostsfile_entry ‘x.x.x.x’ do
31: hostname 'blah2.blah’
32: aliases 'blah2’
33: action :create_if_missing

[2016-02-10T10:27:31+00:00] ERROR: Running exception handlers
[2016-02-10T10:27:31+00:00] ERROR: Exception handlers complete
[2016-02-10T10:27:31+00:00] FATAL: Stacktrace dumped to /var/chef/runs/02e3fa28-25c3-42ff-a90e-d6690118f492/local-mode-cache/cache/chef-stacktrace.out
[2016-02-10T10:27:31+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-02-10T10:27:31+00:00] ERROR: Undefined node attribute or method hostsfile_entry' onnode’
[2016-02-10T10:27:32+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

The cookbook i am using is stored like this:

├── attributes
│ └── default.rb
├── libraries
│ ├── entry.rb
│ ├── manipulator.rb
│ └── matchers.rb
├── metadata.json
├── metadata.rb
├── providers
│ └── entry.rb
├── recipes
│ └── default.rb
└── resources
└── entry.rb

Any idea why it can’t find the resource?



So your opswork stack has been set up to:

  1. have the ‘Use custom Chef cookbooks’ option on
  2. You’ve specified a cookbook bundle via github or S3 or something which
    contains your monorepo, including the hostsfile cookbook (or it’s in a
    Berksfile for the Chef 11.10 stack)


I am using our github server to store the cookbooks. All other cookbooks work fine apart from this one. I am also using a Chef 12 stack in opsWorks, which this cookbook may not support?


Nah, the hostfile cookbook definitely works in Chef 12.

You might need to SSH onto the box which has the failing Chef run and make
sure that it’s actually downloading the hostsfile cookbook into the
directory that the Chef run uses for cookbooks, I’m not sure how Opsworks
works out what cookbook to send where or if it just sends them all

Is the hostsfile cookbook somewhere in your dependency tree (i.e. the
cookbook that tries to use the hostsfile_entry resource on a lifecycle
event has depends ‘hostsfile’ in its metadata.rb)?

Does your opsworks stack point to the right branch in github?