A reclass clone from scratch with additional features
Olivier Mauras 02ec9817c4 Forgot to process states included in node definition 2 years ago
examples Address empty states corner case 2 years ago
salt Forgot to process states included in node definition 2 years ago
README.md REAME: Note that minion_id is available in jinja's scope 2 years ago

README.md

SaltClass

SaltClass is an ENC - External Node Classifier - for Salt that mimics the bahaviour of reclass adding several features on top from this salt centric clone.

The problem of this clone, is that the salt centric code, breaks the compatibility of reclass with Ansible and Puppet and requires Salt ext_pillar/master_tops modules modifications that make them incompatible with reclass.

As pushing these modifications upstream would requires a huge amount of work that wouldn't necessarily be accepted by the actual maintainers, I have decided to remake the same reclass' behaviour on a new codebase that would be, salt only, easy to maintain and easy to modify.

Salt PR can be seen here: https://github.com/saltstack/salt/pull/42349

Features

  • Define your nodes through class inheritance
  • Provide Salt ext_pillar and master_tops from a single entry point
  • Reuse your reclass datas with minimal modifications
    • applications => states
    • parameters => pillars
  • Use Jinja templating in your yaml definitions
  • Access to the following Salt objects for even more flexibility
    • __opts__
    • __salt__
    • __grains__
    • __pillars__
    • minion_id
  • Chose how to merge or override your lists using ^ character (see examples)
  • Expand variables ${} with possibility to escape them if needed \${} (see examples)
  • Ignores missing node/class and will simply return empty - will be logged as warning in salt-master logs

Examples

Basic jinja + grains example

# /srv/saltclass/nodes/minion.domain.yml
environment: prod
classes:
{% for class in ['default', 'app1'] %}
  - {{ class }}
{% endfor %}
  - {{ __grains__['os'] }}

pillars:
  default:
    network:
      dns:
        srv3: 192.168.1.1
    os: {{ __grains__['oscodename'] }}

List merge example

# /srv/saltclass/classes/list.yml
pillars:
  list:
    - v1
    - v2

# /srv/saltclass/nodes/minion.domain.yml
classes:
  - list

pillars:
  list:
    - v3
    - v4
# This list will be appended to the one from list class and you will end up with:
# list:
#   - v1
#   - v2
#   - v3
#   - v4
# To override the list use ^ as your first list entry
pillars:
  list:
    - ^
    - v1
    - v4
    - v5
# Will give you:
# list:
#   - v1
#   - v4
#   - v3

Variables expansion

# _test/classes/default.yml
pillars:
  default:
    test:
      list:
        - l1
        - l2
        - l3
      test2: data
  default2:
    expansion:
      going:
        down:
          some: more

# _test/nodes/alpine.internal.yml
pillars:
  borg:
    server: other.xxx.xxx
  override:
    testing:
      variable:
        string: ${default2:expansion:going:down:some}               # Will be expanded to 'more'
        list_: ${default:test2:list}                                # Will be expanded to ['l1', 'l2', 'l3']
        inline_expansion: 'borg server is ${borg:server}'           # Will be expanded to 'borg server is other.xxx.xxx'
        inline_expansion_escape: 'borg server is \${borg:server}'   # Will be expanded to 'borg server is ${borg:server}'
        unknown_expansion: ${class4:unknown:variables}              # Will be expanded to '${class4:unknown:variables}'

TODO

  • Find beta testers :)
  • Make better test/example data