patternMinor
Assertions and constraints
Viewed 0 times
andconstraintsassertions
Problem
I'm constructing a template to build a configuration file, and the service that consumes this file places constraints on identifier lengths.
If an identifier is longer than, say, 6 characters, the service will get part-way through applying the configuration, fail, and leave the node in an inconsistent state.
How can I perform an assertion to trigger a deployment transaction failure, preventing the target nodes' service from being misconfigured?
My particular circumstance is Salt, but I would be curious to see how other systems solve the problem as well.
If an identifier is longer than, say, 6 characters, the service will get part-way through applying the configuration, fail, and leave the node in an inconsistent state.
How can I perform an assertion to trigger a deployment transaction failure, preventing the target nodes' service from being misconfigured?
My particular circumstance is Salt, but I would be curious to see how other systems solve the problem as well.
Solution
In Ansible: you can use
In Puppet: there is fail function evaluated during parsing phase which cause parsing failure on server (see question on StackOverflow)
assert or fail module. - name: "Make sure web_sites is dictionary"
fail: msg="web_sites should be dictionary"
when: web_sites is not dict
- name: "cluster_name should be shorter than 6 chars"
assert:
that: cluster_name|len <= 6In Puppet: there is fail function evaluated during parsing phase which cause parsing failure on server (see question on StackOverflow)
if length($cluster_name) > 6 {
fail("Cluster name is too long. Should be less than 6 chars.")
}Code Snippets
- name: "Make sure web_sites is dictionary"
fail: msg="web_sites should be dictionary"
when: web_sites is not dict
- name: "cluster_name should be shorter than 6 chars"
assert:
that: cluster_name|len <= 6if length($cluster_name) > 6 {
fail("Cluster name is too long. Should be less than 6 chars.")
}Context
StackExchange DevOps Q#1010, answer score: 7
Revisions (0)
No revisions yet.