OpsWorks Databags & berkshelf
OpsWorks Stacks Data Bag Reference
- OpsWorks Stacks exposes settings to recipes as Chef data bag content.
- A data bag is a Chef concept.
- It is a global variable stored as JSON data on an instance
- the JSON data is accessible from Chef.
- Like data bag stores global variables as
- app’s source URL
- instance’s hostname
- associated stack’s VPC identifier.
- OpsWorks Stacks stores its data bags on each stack’s instances.
- On Linux instances, data bags is at /var/chef/runs/run-ID/data_bags directory.
- On Windows instances, data bags is at drive:\chef\runs\run-id\data_bags directory.
- These directories include a set of data bags (subdirectories).
- Each data bag contains zero or more data bag items, and are JSON-formatted files that having sets of data bag content.
Data bag content includes
- String content
- It follows Ruby syntax
- can use single or double quotes
- strings with special characters must have double quotes.
- Boolean content
- It is either true or false (no quotes).
- Number content
- It is either integer or decimal numbers, such as 4 or 2.5 (no quotes).
- List content
- Has the form of comma-separated values enclosed in square brackets (no quotes), such as [ ’80’, ‘443’ ]
- JSON objects
- which contain additional data bag content, such as “my-app”: {“elastic_ip”: null,…}.
Chef recipes can access through Chef search or directly, following
- data bags
- data bag items
- data bag content
Search indexes to use to access a data bag through Chef search by OpsWorks Stacks
- aws_opsworks_app, which represents a set of deployed apps for a stack.
- aws_opsworks_command, which represents a set of commands that were run on a stack.
- aws_opsworks_ecs_cluster, which represents a set of Amazon Elastic Container Service (Amazon ECS) cluster instances for a stack.
- aws_opsworks_elastic_load_balancer, which represents a set of Elastic Load Balancing load balancers for a stack.
- aws_opsworks_instance, which represents a set of instances for a stack.
- aws_opsworks_layer, which represents a set of layers for a stack.
- aws_opsworks_rds_db_instance, which represents a set of Amazon Relational Database Service (Amazon RDS) instances for a stack.
- aws_opsworks_stack, which represents a stack.
- aws_opsworks_user, which represents a set of users for a stack.
Berkshelf
- Berkshelf is a dependency manager for Chef cookbooks.
- Easily depend on community cookbooks
- safely include community cookbooks in workflow.
- It is included in ChefDK.
- Running chef generate cookbook, by default, create a Berksfile in the root of the cookbook, alongside the cookbook’s metadata.rb.
Add cookbook’s dependencies to metadata, as
name 'my_first_cookbook'
version '0.1.0'
depends 'apt', '~> 5.0'
The default Berksfile will contain the following:
source 'https://supermarket.chef.io'metadata
AWS Certified DevOps Engineer Free Practice TestTake a Quiz