11

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.

3
  • 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
    – Tensibai
    Apr 24, 2017 at 20:55
  • I'll edit the answer to be a bit less specific. Apr 24, 2017 at 20:58
  • 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. Apr 25, 2017 at 16:42

1 Answer 1

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 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.")
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.