cookbook 'idempotence_file', '~> 1.0.0'
idempotence_file (1) Versions 1.0.0 Follow0
Provides a resource for managing a sentinel file
cookbook 'idempotence_file', '~> 1.0.0', :supermarket
knife supermarket install idempotence_file
knife supermarket download idempotence_file
Idempotence File Cookbook
Maintainer: OIT Systems Engineering (ua-oit-se@alaska.edu)
Purpose
Sentinel files are often used to cheaply detect if some code has run once.
A typical example is shown below.
idempotence_file = File.join('some_dir', 'some_file') apt_update 'Pre-Install Update' do action :update not_if { File.exist?(idempotence_file) } end # Do we remember the dir the first time? directory 'some_dir' do owner 'root' group 'root' mode 0o755 end file idempotence_file do content 'Who cares?' owner 'root' group 'root' mode 0o644 end
Such code is conceptually simple, but verbose and unnecessarily error prone.
Across many cookbooks, such code is also not DRY.
The resource provided by this cookbook reduces the sentinel pattern to two lines of code.
See the example below.
Requirements
Chef
This cookbook requires Chef 14+
Platforms
Supported Platform Families:
- Debian
- Ubuntu, Mint
- Red Hat Enterprise Linux
- Amazon, CentOS, Oracle
- Suse
Platforms validated via Test Kitchen:
- Ubuntu
- Debian
- CentOS
- Oracle
- Fedora
- Amazon
- Suse
Notes:
- This cookbook should support any recent Windows or Linux variant.
Dependencies
This cookbook does not constrain its dependencies because it is intended as a utility library.
It should ultimately be used within a wrapper cookbook.
Resources
This cookbook provides one resources for managing idempotence files.
Both the content and the location of the file are implementation-defined.
A helper is provided for querying the existence of the file.
# Returns true iff the file exists idempotence_file?('Argument must match the name of the idempotence_file')
idempotence_file
An idempotence_file manages a single file.
Actions
Two action are provided.
-
create
- Post condition is that the file exists. -
delete
- Post condition is that the file does not exist.
Attributes
This resource has no attributes.
Recipes
This cookbook includes no recipes.
Attributes
This cookbook references no attributes.
Examples
The idempotence_file
resource can be used as below.
apt_update 'Pre-Install Update' do action :update not_if { idempotence_file?('Pre-Install Update') } end idempotence_file 'Pre-Install Update'
Development
See CONTRIBUTING.md and TESTING.md.
Dependent cookbooks
This cookbook has no specified dependencies.
Contingent cookbooks
Changelog for Idempotence File Cookbook
1.0.0
- Initial release
Collaborator Number Metric
1.0.0 failed this metric
Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.
Contributing File Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file
Foodcritic Metric
1.0.0 passed this metric
No Binaries Metric
1.0.0 passed this metric
Testing File Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
1.0.0 failed this metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file
Foodcritic Metric
1.0.0 passed this metric
No Binaries Metric
1.0.0 passed this metric
Testing File Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
1.0.0 passed this metric
1.0.0 passed this metric
Testing File Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
1.0.0 failed this metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number