Overriding Cookbook Attribute in Vagrantfile Custom JSON Data

孤者浪人 提交于 2019-12-05 22:10:38

Not entirely clear what the question is, but I'll assume you're trying to write a wrapper cookbook that installs a more modern version of Maven.

The trick is to set "normal" attributes in the wrapper cookbook which will override the "default" attributes of maven cookbook. For more details read about chef's attribute precedence

This is a better than providing run-time parameters, for the following reasons:

  1. You are writing a wrapper cookbook, so an attribute file would be the natural place to set values
  2. The "maven" cookbook requires setting 4 attributes to specify a new Maven version.

Hope this helps.

Example

├── attributes
│   └── maven.rb
├── Berksfile
├── Berksfile.lock
├── metadata.rb
├── recipes
│   └── default.rb
└── Vagrantfile

metadata.rb

name             'maven_custom'
maintainer       'YOUR_NAME'
maintainer_email 'YOUR_EMAIL'
license          'All rights reserved'
description      'Installs/Configures maven_custom'
long_description 'Installs/Configures maven_custom'
version          '0.1.0'

depends "apt"
depends "maven"

attributes/maven.rb

normal['maven']['version'] = 3
normal['maven']['3']['version'] = '3.2.1'
normal['maven']['3']['url'] = 'http://www.eu.apache.org/dist/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz'
normal['maven']['3']['checksum'] = 'cdee2fd50b2b4e34e2d67d01ab2018b051542ee759c07354dd7aed6f4f71675c'

recipes/default.rb

#
# Cookbook Name:: maven_custom
# Recipe:: default
#
include_recipe "apt"
include_recipe "maven"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!