How to show a custom error in Jinja2 macro or cmd state?

424 views
Skip to first unread message

Quan Tong Anh

unread,
Feb 14, 2014, 12:15:10 AM2/14/14
to salt-...@googlegroups.com
I'm going to write a macro to build a local repository on Ubuntu using debmirror.

Here's a snippet:

keyring_import:
  cmd:
    - run
{%- if 'keyid' in kwargs and 'keyserver' in kwargs %}
    {%- set keyid = kwargs.pop('keyid', None) %}
    {%- set keyserver = kwargs.pop('keyserver', None) %}
    - name: 'gpg --no-default-keyring --keyring {{ gnupghome }}/trustedkeys.gpg --keyserver {{ keyserver }} --recv-keys {{ keyid }}'
{%- elif 'key_url' in kwargs %}
    {%- set key_url = kwargs.pop('key_url') %}
    - name: 'wget -q -O- "{{ key_url }}" | gpg --no-default-keyring --keyring {{ gnupghome }}/trustedkeys.gpg --import'
{%- endif %}
    - require:
      - pkg: wget
      - pkg: gnupg

I want to use `else` instead of `endif` to show a custom error, something like "Either key_url or both keyserver and keyid required".
Is it possible?

Mrten

unread,
Feb 14, 2014, 5:01:00 AM2/14/14
to salt-...@googlegroups.com
I tend to raise (python) exceptions for that, except (ha!) I haven't
found a way to do that in jinja (in Python/mako it is easy).

<% raise Exception("exceptiontext") %>

so perhaps, if you change the renderer to jinja|mako|yaml ?

also, you can insert illegal YAML :)


I actually have an issue open for this:

https://github.com/saltstack/salt/issues/4695

M.
Reply all
Reply to author
Forward
0 new messages