Answers: <p>In Ansible: you can use <code>assert</code> or <code>fail</code> module. </p>
  
  <pre><code>- 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 &lt;= 6
  </code></pre>
  
  <p>In Puppet: there is <a href="https://docs.puppet.com/puppet/latest/function.html#fail" rel="nofollow noreferrer">fail</a> function evaluated during parsing phase which cause parsing failure on server (see <a href="https://stackoverflow.com/questions/7570957/is-it-possible-to-assert-in-puppet">question on StackOverflow</a>) </p>
  
  <pre><code> if length($cluster_name) &gt; 6 {
        fail("Cluster name is too long. Should be less than 6 chars.")
   }
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2017-04-25T07:27:14.943Z
Answers: 2017-04-25T07:27:14.943Z
Answers: 2017-05-23T12:39:34.013Z
Answers: Věroš K.
Body: <p>I'm constructing a template to build a configuration file, and the service that consumes this file places constraints on identifier lengths.</p>
  
  <p>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.</p>
  
  <p>How can I perform an assertion to trigger a deployment transaction failure, preventing the target nodes' service from being misconfigured?</p>
  
  <p>My particular circumstance is Salt, but I would be curious to see how other systems solve the problem as well.</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-04-24T20:55:33.737Z
Comments: Well in chef I'll add a linting rule,  either rspec or foodcritic or ensure the identifier match in the recipe.  No idea for salt,  I don't think there's a gerenic answer as each configuration manager has its own specificity
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-04-24T20:58:03.397Z
Comments: I'll edit the answer to be a bit less specific.
Comments: Michael Mol
Comments: CC BY-SA 3.0
Comments: 2017-04-25T16:42:07.783Z
Comments: At the moment, my current contemplation for a Saltstack+Jinja solution would be a macro that attempts to read from a file that cannot exist. Other renderers would work differently. A Python renderer, for example, would be trivial; simply throw an exception.
Comments: Michael Mol
Tags: <configuration><configuration-management><linting>
Title: Assertions and constraints
UserDisplayName: Michael Mol
ThreadText: # Assertions and constraints
  
  (Asked by: username_0 on 2017-04-24)
  
  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.
  
  **Tags:** configuration, configuration-management, linting
  
  > **Comments:**
  > **username_1**: Well in chef I'll add a linting rule,  either rspec or foodcritic or ensure the identifier match in the recipe.  No idea for salt,  I don't think there's a gerenic answer as each configuration manager has its own specificity  
  > **username_0**: I'll edit the answer to be a bit less specific.  
  > **username_0**: At the moment, my current contemplation for a Saltstack+Jinja solution would be a macro that attempts to read from a file that cannot exist. Other renderers would work differently. A Python renderer, for example, would be trivial; simply throw an exception.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-04-25. Score: 7
  
  In Ansible: you can use `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 <= 6
  
  ```
  
  In Puppet: there is [fail](https://docs.puppet.com/puppet/latest/function.html#fail) function evaluated during parsing phase which cause parsing failure on server (see [question on StackOverflow](https://stackoverflow.com/questions/7570957/is-it-possible-to-assert-in-puppet))
  
  ```
   if length($cluster_name) > 6 {
        fail("Cluster name is too long. Should be less than 6 chars.")
   }
  
  ```
  
  
  ---
  
  