simpkv::delete
: Deletes akey
from the configured backend.simpkv::deletetree
: Deletes a whole folder from the configured backend.simpkv::exists
: Returns whether key or key folder exists in the configured backend.simpkv::get
: Retrieves the value and any metadata stored atkey
from the configured backend.simpkv::list
: Returns a listing of all keys and sub-folders in a folder. The list operation does not recurse through any sub-folders. Only information abosimpkv::put
: Sets the data atkey
to the specifiedvalue
in the configured backend. Optionally sets metadata along with thevalue
.simpkv::support::config::merge
: Create merged backend configuration and then validate it. The merge entails the following operations: * Theoptions
argument is merged witsimpkv::support::config::validate
: Validate backend configurationsimpkv::support::key::validate
: Validates key conforms to the simpkv key specification * simpkv key specification * Key must contain only the following characters:simpkv::support::load
: Load simpkv adapter and plugins and add simpkv 'extension' to the catalog instance, if it is not present
Type: Ruby 4.x API
Deletes a key
from the configured backend.
simpkv::delete("hosts/${facts['fqdn']}")
simpkv::delete("hosts/${facts['fqdn']}", { 'app_id' => 'myapp' })
simpkv::delete("hosts/${facts['fqdn']}", { 'global' => true })
Deletes a key
from the configured backend.
Returns: Boolean
true
when backend operation succeeds; false
when the
backend operation fails and 'softfail' is true
in the merged backend
options
Raises:
ArgumentError
If the key or merged backend config is invalidLoadError
If the simpkv adapter cannot be loadedRuntimeError
If the backend operation fails, unless 'softfail' istrue
in the merged backend options.
simpkv::delete("hosts/${facts['fqdn']}")
simpkv::delete("hosts/${facts['fqdn']}", { 'app_id' => 'myapp' })
simpkv::delete("hosts/${facts['fqdn']}", { 'global' => true })
Data type: String[1]
The key to remove. Must conform to the following:
-
Key must contain only the following characters:
- a-z
- 0-9
- The following special characters:
._:-/
-
Key may not contain '/./' or '/../' sequences.
Data type: Optional[Hash]
simpkv configuration that will be merged with
simpkv::options
. All keys are optional.
Options:
-
'app_id'
String
: Specifies an application name that can be used to identify which backend configuration to use via fuzzy name matching, in the absence of thebackend
option.- More flexible option than
backend
. - Useful for grouping together simpkv function calls found in different catalog resources.
- When specified and the
backend
option is absent, the backend will be selected preferring a backend in the mergedbackends
option whose name exactly matches theapp_id
, followed by the longest backend name that matches the beginning of theapp_id
, followed by thedefault
backend. - When absent and the
backend
option is also absent, this function will use thedefault
backend.
- More flexible option than
-
'backend'
String
: Definitive name of the backend to use.- Takes precedence over
app_id
. - When present, must match a key in the
backends
option of the merged options Hash or the function will fail. - When absent in the merged options, this function will select
the backend as described in the
app_id
option.
- Takes precedence over
-
'backends'
Hash
: Hash of backend configurations-
Each backend configuration in the merged options Hash must be a Hash that has the following keys:
type
: Backend type.id
: Unique name for the instance of the backend. (Same backend type can be configured differently).
-
Other keys for configuration specific to the backend may also be present.
-
-
'global'
Boolean
: Set totrue
when the key being accessed is global. Otherwise, the key will be tied to the Puppet environment of the node whose manifest is being compiled.- Defaults to
false
- Defaults to
-
'softfail'
Boolean
: Whether to ignore simpkv operation failures.- When
true
, this function will return a result even when the operation failed at the backend. - When
false
, this function will fail when the backend operation failed. - Defaults to
false
.
- When
Type: Ruby 4.x API
Deletes a whole folder from the configured backend.
simpkv::deletetree("hosts")
simpkv::deletetree("hosts", { 'app_id' => 'myapp' })
simpkv::deletetree("hosts", { 'global' => true })
Deletes a whole folder from the configured backend.
Returns: Boolean
true
when backend operation succeeds; false
when the
backend operation fails and 'softfail' is true
in the merged backend
options
Raises:
ArgumentError
If the key folder or merged backend config is invalidLoadError
If the simpkv adapter cannot be loadedRuntimeError
If the backend operation fails, unless 'softfail' istrue
in the merged backend options.
simpkv::deletetree("hosts")
simpkv::deletetree("hosts", { 'app_id' => 'myapp' })
simpkv::deletetree("hosts", { 'global' => true })
Data type: String[1]
The key folder to remove. Must conform to the following:
-
Key folder must contain only the following characters:
- a-z
- 0-9
- The following special characters:
._:-/
-
Key folder may not contain '/./' or '/../' sequences.
Data type: Optional[Hash]
simpkv configuration that will be merged with
simpkv::options
. All keys are optional.
Options:
-
'app_id'
String
: Specifies an application name that can be used to identify which backend configuration to use via fuzzy name matching, in the absence of thebackend
option.- More flexible option than
backend
. - Useful for grouping together simpkv function calls found in different catalog resources.
- When specified and the
backend
option is absent, the backend will be selected preferring a backend in the mergedbackends
option whose name exactly matches theapp_id
, followed by the longest backend name that matches the beginning of theapp_id
, followed by thedefault
backend. - When absent and the
backend
option is also absent, this function will use thedefault
backend.
- More flexible option than
-
'backend'
String
: Definitive name of the backend to use.- Takes precedence over
app_id
. - When present, must match a key in the
backends
option of the merged options Hash or the function will fail. - When absent in the merged options, this function will select
the backend as described in the
app_id
option.
- Takes precedence over
-
'backends'
Hash
: Hash of backend configurations-
Each backend configuration in the merged options Hash must be a Hash that has the following keys:
type
: Backend type.id
: Unique name for the instance of the backend. (Same backend type can be configured differently).
-
Other keys for configuration specific to the backend may also be present.
-
-
'global'
Boolean
: Set totrue
when the key being accessed is global. Otherwise, the key will be tied to the Puppet environment of the node whose manifest is being compiled.- Defaults to
false
- Defaults to
-
'softfail'
Boolean
: Whether to ignore simpkv operation failures.- When
true
, this function will return a result even when the operation failed at the backend. - When
false
, this function will fail when the backend operation failed. - Defaults to
false
.
- When
Type: Ruby 4.x API
Returns whether key or key folder exists in the configured backend.
if simpkv::exists("hosts/${facts['fqdn']}") {
notify { "hosts/${facts['fqdn']} exists": }
}
if simpkv::exists("hosts/${facts['fqdn']}", { 'app_id' => 'myapp' }) {
notify { "hosts/${facts['fqdn']} exists": }
}
if simpkv::exists("hosts", { 'global' => true}) {
notify { 'hosts folder exists': }
}
Returns whether key or key folder exists in the configured backend.
Returns: Enum[Boolean,Undef]
If the backend operation succeeds, returns
true
or false
; if the backend operation fails and 'softfail' is true
in the merged backend options, returns nil
Raises:
ArgumentError
If the key or merged backend config is invalidLoadError
If the simpkv adapter cannot be loadedRuntimeError
If the backend operation fails, unless 'softfail' istrue
in the merged backend options.
if simpkv::exists("hosts/${facts['fqdn']}") {
notify { "hosts/${facts['fqdn']} exists": }
}
if simpkv::exists("hosts/${facts['fqdn']}", { 'app_id' => 'myapp' }) {
notify { "hosts/${facts['fqdn']} exists": }
}
if simpkv::exists("hosts", { 'global' => true}) {
notify { 'hosts folder exists': }
}
Data type: String[1]
The key or key folder to check. Must conform to the following:
-
Key must contain only the following characters:
- a-z
- 0-9
- The following special characters:
._:-/
-
Key may not contain '/./' or '/../' sequences.
Data type: Optional[Hash]
simpkv configuration that will be merged with
simpkv::options
. All keys are optional.
Options:
-
'app_id'
String
: Specifies an application name that can be used to identify which backend configuration to use via fuzzy name matching, in the absence of thebackend
option.- More flexible option than
backend
. - Useful for grouping together simpkv function calls found in different catalog resources.
- When specified and the
backend
option is absent, the backend will be selected preferring a backend in the mergedbackends
option whose name exactly matches theapp_id
, followed by the longest backend name that matches the beginning of theapp_id
, followed by thedefault
backend. - When absent and the
backend
option is also absent, this function will use thedefault
backend.
- More flexible option than
-
'backend'
String
: Definitive name of the backend to use.- Takes precedence over
app_id
. - When present, must match a key in the
backends
option of the merged options Hash or the function will fail. - When absent in the merged options, this function will select
the backend as described in the
app_id
option.
- Takes precedence over
-
'backends'
Hash
: Hash of backend configurations-
Each backend configuration in the merged options Hash must be a Hash that has the following keys:
type
: Backend type.id
: Unique name for the instance of the backend. (Same backend type can be configured differently).
-
Other keys for configuration specific to the backend may also be present.
-
-
'global'
Boolean
: Set totrue
when the key being accessed is global. Otherwise, the key will be tied to the Puppet environment of the node whose manifest is being compiled.- Defaults to
false
- Defaults to
-
'softfail'
Boolean
: Whether to ignore simpkv operation failures.- When
true
, this function will return a result even when the operation failed at the backend. - When
false
, this function will fail when the backend operation failed. - Defaults to
false
.
- When
Type: Ruby 4.x API
Retrieves the value and any metadata stored at key
from the
configured backend.
$result = simpkv::get("database/${facts['fqdn']}")
class { 'wordpress':
db_host => $result['value'],
db_info => $result['metadata']
}
$result = simpkv::get("database/${facts['fqdn']}", { 'app_id' => 'myapp' })
class { 'wordpress':
db_host => $result['value'],
db_info => $result['metadata']
}
$result = simpkv::get("database/${facts['fqdn']}", { 'global' => true })
class { 'wordpress':
db_host => $result['value'],
db_info => $result['metadata']
}
Retrieves the value and any metadata stored at key
from the
configured backend.
Returns: Enum[Hash,Undef]
Hash containing the value and any metadata upon
success; Undef when the backend operation fails and 'softfail' is true
in the merged backend options
- Hash will have a 'value' key containing the retrieved value
- Hash may have a 'metadata' key containing a Hash with any metadata for the key
Raises:
ArgumentError
If the key or merged backend config is invalidLoadError
If the simpkv adapter cannot be loadedRuntimeError
If the backend operation fails, unless 'softfail' istrue
in the merged backend options.
$result = simpkv::get("database/${facts['fqdn']}")
class { 'wordpress':
db_host => $result['value'],
db_info => $result['metadata']
}
$result = simpkv::get("database/${facts['fqdn']}", { 'app_id' => 'myapp' })
class { 'wordpress':
db_host => $result['value'],
db_info => $result['metadata']
}
$result = simpkv::get("database/${facts['fqdn']}", { 'global' => true })
class { 'wordpress':
db_host => $result['value'],
db_info => $result['metadata']
}
Data type: String[1]
The key to retrieve. Must conform to the following:
-
Key must contain only the following characters:
- a-z
- 0-9
- The following special characters:
._:-/
-
Key may not contain '/./' or '/../' sequences.
Data type: Optional[Hash]
simpkv configuration that will be merged with
simpkv::options
. All keys are optional.
Options:
-
'app_id'
String
: Specifies an application name that can be used to identify which backend configuration to use via fuzzy name matching, in the absence of thebackend
option.- More flexible option than
backend
. - Useful for grouping together simpkv function calls found in different catalog resources.
- When specified and the
backend
option is absent, the backend will be selected preferring a backend in the mergedbackends
option whose name exactly matches theapp_id
, followed by the longest backend name that matches the beginning of theapp_id
, followed by thedefault
backend. - When absent and the
backend
option is also absent, this function will use thedefault
backend.
- More flexible option than
-
'backend'
String
: Definitive name of the backend to use.- Takes precedence over
app_id
. - When present, must match a key in the
backends
option of the merged options Hash or the function will fail. - When absent in the merged options, this function will select
the backend as described in the
app_id
option.
- Takes precedence over
-
'backends'
Hash
: Hash of backend configurations-
Each backend configuration in the merged options Hash must be a Hash that has the following keys:
type
: Backend type.id
: Unique name for the instance of the backend. (Same backend type can be configured differently).
-
Other keys for configuration specific to the backend may also be present.
-
-
'global'
Boolean
: Set totrue
when the key being accessed is global. Otherwise, the key will be tied to the Puppet environment of the node whose manifest is being compiled.- Defaults to
false
- Defaults to
-
'softfail'
Boolean
: Whether to ignore simpkv operation failures.- When
true
, this function will return a result even when the operation failed at the backend. - When
false
, this function will fail when the backend operation failed. - Defaults to
false
.
- When
Type: Ruby 4.x API
Returns a listing of all keys and sub-folders in a folder.
The list operation does not recurse through any sub-folders. Only information about the specified key folder is returned.
$result = simpkv::list('hosts')
$result['keys'].each |$host, $info | {
host { $host:
ip => $info['value'],
}
}
$result = simpkv::list('applications', { 'app_id' => 'myapp' })
notice("Supported applications: ${join($result['folders'], ' ')}")
$result = simpkv::list('/', { 'global' = true })
notice("Global folders: ${join($result['folders'], ' ')}")
$result['keys'].each |$key, $info | {
notice("Global key ${key}: value=${info['value']} metadata=${info['metadata']}")
}
Returns a listing of all keys and sub-folders in a folder.
The list operation does not recurse through any sub-folders. Only information about the specified key folder is returned.
Returns: Enum[Hash,Undef]
Hash containing the key/info pairs and list of
sub-folders upon success; Undef when the backend operation fails and
'softfail' is true
in the merged backend options
- 'keys' attribute is a Hash of the key information in the folder
- Each Hash key is a key found in the folder
- Each Hash value is a Hash with a 'value' key and an optional 'metadata' key.
- 'folders' attribute is an Array of sub-folder names
Raises:
ArgumentError
If the key folder or merged backend config is invalidLoadError
If the simpkv adapter cannot be loadedRuntimeError
If the backend operation fails, unless 'softfail' istrue
in the merged backend options.
$result = simpkv::list('hosts')
$result['keys'].each |$host, $info | {
host { $host:
ip => $info['value'],
}
}
$result = simpkv::list('applications', { 'app_id' => 'myapp' })
notice("Supported applications: ${join($result['folders'], ' ')}")
$result = simpkv::list('/', { 'global' = true })
notice("Global folders: ${join($result['folders'], ' ')}")
$result['keys'].each |$key, $info | {
notice("Global key ${key}: value=${info['value']} metadata=${info['metadata']}")
}
Data type: String[1]
The key folder to list. Must conform to the following:
-
Key folder must contain only the following characters:
- a-z
- 0-9
- The following special characters:
._:-/
-
Key folder may not contain '/./' or '/../' sequences.
Data type: Optional[Hash]
simpkv configuration that will be merged with
simpkv::options
. All keys are optional.
Options:
-
'app_id'
String
: Specifies an application name that can be used to identify which backend configuration to use via fuzzy name matching, in the absence of thebackend
option.- More flexible option than
backend
. - Useful for grouping together simpkv function calls found in different catalog resources.
- When specified and the
backend
option is absent, the backend will be selected preferring a backend in the mergedbackends
option whose name exactly matches theapp_id
, followed by the longest backend name that matches the beginning of theapp_id
, followed by thedefault
backend. - When absent and the
backend
option is also absent, this function will use thedefault
backend.
- More flexible option than
-
'backend'
String
: Definitive name of the backend to use.- Takes precedence over
app_id
. - When present, must match a key in the
backends
option of the merged options Hash or the function will fail. - When absent in the merged options, this function will select
the backend as described in the
app_id
option.
- Takes precedence over
-
'backends'
Hash
: Hash of backend configurations-
Each backend configuration in the merged options Hash must be a Hash that has the following keys:
type
: Backend type.id
: Unique name for the instance of the backend. (Same backend type can be configured differently).
-
Other keys for configuration specific to the backend may also be present.
-
-
'global'
Boolean
: Set totrue
when the key being accessed is global. Otherwise, the key will be tied to the Puppet environment of the node whose manifest is being compiled.- Defaults to
false
- Defaults to
-
'softfail'
Boolean
: Whether to ignore simpkv operation failures.- When
true
, this function will return a result even when the operation failed at the backend. - When
false
, this function will fail when the backend operation failed. - Defaults to
false
.
- When
Type: Ruby 4.x API
Sets the data at key
to the specified value
in the configured backend.
Optionally sets metadata along with the value
.
simpkv::put("hosts/${facts['clientcert']}", $facts['ipaddress'])
$meta = { 'rack_id' => 183 }
$opts = { 'app_id' => 'myapp' }
simpkv::put("hosts/${facts['clientcert']}", $facts['ipaddress'], $meta, $opts)
simpkv::put("hosts/${facts['clientcert']}", $facts['ipaddress'], { 'global' => true })
Sets the data at key
to the specified value
in the configured backend.
Optionally sets metadata along with the value
.
Returns: Boolean
true
when backend operation succeeds; false
when the
backend operation fails and 'softfail' is true
in the merged backend
options
Raises:
ArgumentError
If the key or merged backend config is invalidLoadError
If the simpkv adapter cannot be loadedRuntimeError
If the backend operation fails, unless 'softfail' istrue
in the merged backend options.
simpkv::put("hosts/${facts['clientcert']}", $facts['ipaddress'])
$meta = { 'rack_id' => 183 }
$opts = { 'app_id' => 'myapp' }
simpkv::put("hosts/${facts['clientcert']}", $facts['ipaddress'], $meta, $opts)
simpkv::put("hosts/${facts['clientcert']}", $facts['ipaddress'], { 'global' => true })
Data type: String[1]
The key to set. Must conform to the following:
-
Key must contain only the following characters:
- a-z
- 0-9
- The following special characters:
._:-/
-
Key may not contain '/./' or '/../' sequences.
Data type: NotUndef
The value of the key
Data type: Optional[Hash]
Additional information to be persisted
Data type: Optional[Hash]
simpkv configuration that will be merged with
simpkv::options
. All keys are optional.
Options:
-
'app_id'
String
: Specifies an application name that can be used to identify which backend configuration to use via fuzzy name matching, in the absence of thebackend
option.- More flexible option than
backend
. - Useful for grouping together simpkv function calls found in different catalog resources.
- When specified and the
backend
option is absent, the backend will be selected preferring a backend in the mergedbackends
option whose name exactly matches theapp_id
, followed by the longest backend name that matches the beginning of theapp_id
, followed by thedefault
backend. - When absent and the
backend
option is also absent, this function will use thedefault
backend.
- More flexible option than
-
'backend'
String
: Definitive name of the backend to use.- Takes precedence over
app_id
. - When present, must match a key in the
backends
option of the merged options Hash or the function will fail. - When absent in the merged options, this function will select
the backend as described in the
app_id
option.
- Takes precedence over
-
'backends'
Hash
: Hash of backend configurations-
Each backend configuration in the merged options Hash must be a Hash that has the following keys:
type
: Backend type.id
: Unique name for the instance of the backend. (Same backend type can be configured differently).
-
Other keys for configuration specific to the backend may also be present.
-
-
'global'
Boolean
: Set totrue
when the key being accessed is global. Otherwise, the key will be tied to the Puppet environment of the node whose manifest is being compiled.- Defaults to
false
- Defaults to
-
'softfail'
Boolean
: Whether to ignore simpkv operation failures.- When
true
, this function will return a result even when the operation failed at the backend. - When
false
, this function will fail when the backend operation failed. - Defaults to
false
.
- When
Type: Ruby 4.x API
Create merged backend configuration and then validate it.
The merge entails the following operations:
-
The
options
argument is merged withsimpkv::options
Hiera and global simpkv defaults. -
If the
backend
options is missing in the merged options, it is set to a value determined as follows:- If the
app_id
option is present and the name of a backend inbackends
matchesapp_id
,backend
will be set toapp_id
. - Otherwise, if the
app_id
option is present and the name of a backend inbackends
matches the beginning ofapp_id
,backend
will be set to that partially-matching backend name. When multiple backends satisfy the 'start with' match, the backend with the most matching characters is selected. - Otherwise, if the
app_id
option does not match any backend name or is not present,backend
will be set todefault
.
- If the
-
If the
backends
option is missing in the merged options, it is set to a Hash containing a single entry,default
, that has configuration for the simpkv 'file' backend.
Validation includes the following checks:
- configuration for the selected backend exists
- the plugin for the selected backend has been loaded
- different configuration for a specific plugin instance does not exist
Create merged backend configuration and then validate it.
The merge entails the following operations:
-
The
options
argument is merged withsimpkv::options
Hiera and global simpkv defaults. -
If the
backend
options is missing in the merged options, it is set to a value determined as follows:- If the
app_id
option is present and the name of a backend inbackends
matchesapp_id
,backend
will be set toapp_id
. - Otherwise, if the
app_id
option is present and the name of a backend inbackends
matches the beginning ofapp_id
,backend
will be set to that partially-matching backend name. When multiple backends satisfy the 'start with' match, the backend with the most matching characters is selected. - Otherwise, if the
app_id
option does not match any backend name or is not present,backend
will be set todefault
.
- If the
-
If the
backends
option is missing in the merged options, it is set to a Hash containing a single entry,default
, that has configuration for the simpkv 'file' backend.
Validation includes the following checks:
- configuration for the selected backend exists
- the plugin for the selected backend has been loaded
- different configuration for a specific plugin instance does not exist
Returns: Hash
merged simpkv options that will have the backend to use
specified by 'backend'
Raises:
ArgumentError
if merged configuration fails validation
Data type: Hash
Hash that specifies simpkv backend options to be merged with
simpkv::options
.
Data type: Array
List of backends for which plugins have been successfully loaded.
Type: Ruby 4.x API
Validate backend configuration
Validate backend configuration
Returns: Nil
Raises:
ArgumentError
if a backend has not been specified, appropriate configuration for a specified backend cannot be found, or different backend configurations are provided for the same ['type', 'id'] pair.
Data type: Hash
Hash that specifies simpkv backend options
Data type: Array
List of backends for which plugins have been successfully loaded.
Type: Ruby 4.x API
Validates key conforms to the simpkv key specification
-
simpkv key specification
-
Key must contain only the following characters:
- a-z
- 0-9
- The following special characters:
._:-/
-
Key may not contain '/./' or '/../' sequences.
-
-
Terminates catalog compilation if validation fails.
simpkv::support::key::validate('looks/like/a/file/path')
simpkv::support::key::validate('looks/like/a/directory/path/')
simpkv::support::key::validate('simp-simp_snmpd:password.auth')
simpkv::support::key::validate('Uppercase/Characters/NOT/Allowed')
simpkv::support::key::validate('${special}/chars/not/allowed!'}
simpkv::support::key::validate('looks/like/an/./unexpanded/linux/path')
simpkv::support::key::validate('looks/like/another/../unexpanded/linux/path')
Validates key conforms to the simpkv key specification
-
simpkv key specification
-
Key must contain only the following characters:
- a-z
- 0-9
- The following special characters:
._:-/
-
Key may not contain '/./' or '/../' sequences.
-
-
Terminates catalog compilation if validation fails.
Returns: Nil
Raises:
ArgumentError
if validation fails
simpkv::support::key::validate('looks/like/a/file/path')
simpkv::support::key::validate('looks/like/a/directory/path/')
simpkv::support::key::validate('simp-simp_snmpd:password.auth')
simpkv::support::key::validate('Uppercase/Characters/NOT/Allowed')
simpkv::support::key::validate('${special}/chars/not/allowed!'}
simpkv::support::key::validate('looks/like/an/./unexpanded/linux/path')
simpkv::support::key::validate('looks/like/another/../unexpanded/linux/path')
Data type: String[1]
simpkv key
Type: Ruby 4.x API
Load simpkv adapter and plugins and add simpkv 'extension' to the catalog instance, if it is not present
Load simpkv adapter and plugins and add simpkv 'extension' to the catalog instance, if it is not present
Returns: Nil
Raises:
LoadError
if simpkv adapter software fails to load