Forge Home

dotenv

Manage .env configuration files

3,656 downloads

2,951 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 1.0.1 (latest)
  • 1.0.0
released Feb 29th 2020
This version is compatible with:
  • Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2016.4.x
  • Puppet >= 4.10.0 < 7.0.0
  • , , , , , , , , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'spy-dotenv', '1.0.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add spy-dotenv
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install spy-dotenv --version 1.0.1

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

spy/dotenv — version 1.0.1 Feb 29th 2020

Manage .env configuration files

Table of Contents

  1. Description
  2. Setup requirements
  3. Usage - Configuration options and additional functionality
  4. Limitations - OS compatibility, etc.
  5. Credits
  6. Licensing information

Description

This Puppet module provides the dotenv defined type for managing .env files commonly used for storing configuration separately from application code; see the The Twelve-Factor App methodology for details of this concept.

The module also supplies the dotenv function that produces a string representation of .env file contents from a Puppet hash.

Setup Requirements

This module depends on the puppetlabs/stdlib module.

Usage

dotenv defined type

The dotenv defined type has the following attributes:

  • path (namevar) – absolute path to the .env file to manage;
  • ensure (default: present) – manages the file as present or absent;
  • mode (default: undef) – file mode to set (DAC permissions);
  • owner (default: undef) – file owner to set;
  • group (default: undef) – file group to set;
  • force (default: false) – see the force attribute of the underlying file resource type;
  • entries – hash of key-value entries to write into the file.

dotenv function

The dotenv function takes a Puppet hash of key-value entries as its sole parameter and returns a string that represents the corresponding .env file contents.

Please see the last example below for a use case.

Examples

Manage a web application configuration file:

dotenv { 'Web app config':
  path    => '/var/www/app/.env',
  mode    => '0400',
  owner   => 'www-data',
  group   => 'www-data',
  entries => {
    'MYSQL_HOSTNAME' => 'localhost',
    'MYSQL_USERNAME' => 'user',
    'MYSQL_PASSWORD' => 'secret',
    'MYSQL_DATABASE' => 'dbname',
  },
}

The result in the /var/www/app/.env file will be:

# Managed by Puppet

MYSQL_HOSTNAME="localhost"
MYSQL_USERNAME="user"
MYSQL_PASSWORD="secret"
MYSQL_DATABASE="dbname"

Manage a web application configuration file with entries looked up in Hiera:

$entries = lookup('app_env', Hash, deep)

dotenv { 'Web app config':
  path    => '/var/www/app/.env',
  mode    => '0400',
  owner   => 'www-data',
  group   => 'www-data',
  entries => $entries,
}

Previous example using the base file resource type and the dotenv function (in case you might want more control over the resource attributes–note the backup attribute):

$entries = lookup('app_env', Hash, deep)

file { 'Web app config':
  path    => '/var/www/app/.env',
  backup  => false,
  mode    => '0400',
  owner   => 'www-data',
  group   => 'www-data',
  content => dotenv($entries),
}

Limitations

The dotenv defined type is a wrapper around the file resource type and implements a narrow subset of its attributes.

Credits

The dotenv function is a stripped down version of the hash2kv function from the mmckinst/hash2stuff module by Mark McKinstry.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.