Преглед изворни кода

Merge "Add support for jinja2 renderer options. (2018.2)"

pull/73/head
Ondrej Smola пре 6 година
родитељ
комит
ca58be3b2f
7 измењених фајлова са 143 додато и 4 уклоњено
  1. +1
    -1
      .travis.yml
  2. +54
    -1
      README.rst
  3. +23
    -0
      salt/files/_renderer.conf
  4. +6
    -0
      salt/map.jinja
  5. +15
    -1
      salt/master/service.sls
  6. +17
    -1
      salt/minion/service.sls
  7. +27
    -0
      tests/pillar/master_formulas.sls

+ 1
- 1
.travis.yml Прегледај датотеку

@@ -13,7 +13,7 @@ install:
gem 'kitchen-docker'
gem 'kitchen-inspec'
gem 'inspec'
gem 'kitchen-salt', :git => 'https://github.com/salt-formulas/kitchen-salt.git'
gem 'kitchen-salt' #, :git => 'https://github.com/salt-formulas/kitchen-salt.git'
- bundle install

env:

+ 54
- 1
README.rst Прегледај датотеку

@@ -341,7 +341,60 @@ Event to trigger the key removal
salt-call event.send 'salt/key/remove'


Encrypted Pillars
Jinja options
-------------

Use following options to update default jinja renderer options. Salt recognize Jinja options for templates and for sls files.

For full list of options check jinja documentation: http://jinja.pocoo.org/docs/api/#high-level-api.

.. code-block:: yaml


salt:
renderer:
# for templates
jinja: &jina_env
# Default Jinja environment options
block_start_string: '{%'
block_end_string: '%}'
variable_start_string: '{{'
variable_end_string: '}}'
comment_start_string: '{#'
comment_end_string: '#}'
keep_trailing_newline: False
newline_sequence: '\n'

# Next two are enabled by default in Salt
trim_blocks: True
lstrip_blocks: True

# Next two are not enabled by default in Salt
# but worth to consider to enable in future for salt-formulas
line_statement_prefix: '%'
line_comment_prefix: '##'

# for .sls state files
jinja_sls: *jinja_env



With the line_statement/comment* _prefix options enabled following code statements are valid:

.. code-block:: yaml
%- set myvar = 'one'

## You can mix even with '{%'
{%- set myvar = 'two' %} ## comment
%- set mylist = ['one', 'two', 'three'] ## comment

## comment
%- for item in mylist: ## comment
{{- item }}
%- endfor


Encrypted pillars
~~~~~~~~~~~~~~~~~

Note: NACL + below configuration will be available in Salt > 2017.7.

+ 23
- 0
salt/files/_renderer.conf Прегледај датотеку

@@ -0,0 +1,23 @@
{%- from "salt/map.jinja" import renderer with context %}

{%- if renderer.get('jinja_sls', {}) | length > 0 %}

jinja_sls_env:
{% for key, value in renderer.jinja_sls.iteritems() %}
{{ key }}: "{{ value }}"
{%- endfor %}

{%- endif %}

{%- if renderer.get('jinja', {}) | length > 0 %}

jinja_env:
{% for key, value in renderer.jinja.iteritems() %}
{{ key }}: "{{ value }}"
{%- endfor %}

{%- endif %}

{#-
vim: syntax=jinja
-#}

+ 6
- 0
salt/map.jinja Прегледај датотеку

@@ -202,6 +202,12 @@ RedHat:
- pkg-config
{%- endload %}

{%- load_yaml as renderer_defaults %}
default:
renderer: {}
{%- endload %}
{%- set renderer = salt['grains.filter_by'](renderer_defaults, merge=salt['pillar.get']('salt:renderer')) %}

{%- if pillar.salt.control is defined %}
{%- set raw_control = salt['grains.filter_by'](control_specific, merge=salt['pillar.get']('salt:control')) %}
{%- set control = salt['grains.filter_by'](control_common, merge=raw_control) %}

+ 15
- 1
salt/master/service.sls Прегледај датотеку

@@ -1,4 +1,4 @@
{%- from "salt/map.jinja" import master with context %}
{%- from "salt/map.jinja" import master, renderer with context %}
{%- if master.enabled %}

{%- if master.source.get('engine', 'pkg') == 'pkg' %}
@@ -70,6 +70,20 @@ salt_master_packages:

{%- endif %}

{%- if renderer | length > 0 %}

/etc/salt/master.d/_renderer.conf:
file.managed:
- source: salt://salt/files/_renderer.conf
- user: root
- template: jinja
- require:
- {{ master.install_state }}
- watch_in:
- service: salt_master_service

{%- endif %}

salt_master_service:
service.running:
- name: {{ master.service }}

+ 17
- 1
salt/minion/service.sls Прегледај датотеку

@@ -1,4 +1,4 @@
{%- from "salt/map.jinja" import minion with context %}
{%- from "salt/map.jinja" import minion,renderer with context %}
{%- if minion.enabled %}

{%- if minion.source.get('engine', 'pkg') == 'pkg' %}
@@ -92,6 +92,22 @@ salt_minion_{{ service_name }}_dependencies_pip:
{%- endif %}
{%- endfor %}


{%- if renderer | length > 0 %}

/etc/salt/minion.d/_renderer.conf:
file.managed:
- source: salt://salt/files/_renderer.conf
- user: root
- template: jinja
- require:
- {{ minion.install_state }}
- watch_in:
- service: salt_minion_service

{%- endif %}


salt_minion_service:
service.running:
- name: {{ minion.service }}

+ 27
- 0
tests/pillar/master_formulas.sls Прегледај датотеку

@@ -49,3 +49,30 @@ salt:
source: git
address: 'https://github.com/salt-formulas/salt-formula-bind.git'
revision: master
renderer:
jinja:
block_start_string: {{ '"{%"' }}
block_end_string: {{ '"%}"' }}
variable_start_string: {{ '"{{"' }}
variable_end_string: {{ '"}}"' }}
comment_start_string: {{ '"{#"' }}
comment_end_string: {{ '"#}"' }}
keep_trailing_newline: False
newline_sequence: '\n'
trim_blocks: True
lstrip_blocks: True
line_statement_prefix: "%"
line_comment_prefix: "##"
jinja_sls:
block_start_string: {{ '"{%"' }}
block_end_string: {{ '"%}"' }}
variable_start_string: {{ '"{{"' }}
variable_end_string: {{ '"}}"' }}
comment_start_string: {{ '"{#"' }}
comment_end_string: {{ '"#}"' }}
keep_trailing_newline: False
newline_sequence: '\n'
trim_blocks: True
lstrip_blocks: True
line_statement_prefix: "%"
line_comment_prefix: "##"

Loading…
Откажи
Сачувај