- Description
- Setup requirements
- Usage - Configuration options and additional functionality
- Limitations - OS compatibility, etc.
- Credits
- Licensing information
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.
This module depends on the puppetlabs/stdlib module.
The dotenv
defined type has the following attributes:
path
(namevar) – absolute path to the.env
file to manage;ensure
(default:present
) – manages the file aspresent
orabsent
;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 underlyingfile
resource type;entries
– hash of key-value entries to write into the file.
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.
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),
}
The dotenv
defined type is a wrapper around the file
resource type and implements a narrow subset of its attributes.
The dotenv
function is a stripped down version of the hash2kv
function from the mmckinst/hash2stuff
module by Mark McKinstry.
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.