从字典中过滤出键

Filter out key from dictionary

有字典(在map.jinja中定义)

{% set intellij = salt['grains.filter_by']({
    'default': {
        'orig_name': 'idea-IC-145.1617.8',
        'download_url': 'www.example.com',         
        'archive_format': 'tar',
        'archive_opts': 'xfz',
        'owner': 'root',
        'owner_link_location': '/blabla/bin/idea',
    },
}, merge=salt['pillar.get']('intellij')) %}

和一些接受参数的函数定义几乎与字典的键相同(假设 "function" 实际上是一个宏)

{% macro some_macro(state_id, orig_name, download_url, archive_format, owner, archive_opts=None) %}

我想过滤掉一些键,这样我就可以这样调用它:

{{ some_macro('some_state', **intellij) }}

我尝试过各种结构,例如:

{{ some_macro('intellij', **(intellij|rejectattr("owner_link_location"))) }}

产生

Jinja error: call() argument after ** must be a mapping, not generator

Dict-comprehension(而不是 jinja 过滤器)也不起作用。

如何实现上述功能(过滤掉key或者至少用"extracted"和过滤字典简洁调用函数)?

描述的是您遇到的问题here
有一个技巧可以解决,我觉得它很好。

{% macro some_macro(state_id, orig_name, download_url, archive_format, owner, archive_opts=None) -%}
{% if kwargs | length >= 0 -%}
// implement your macro definition here
{% endif -%}
{% endmacro -%}

重点是,如果您没有在映射中使用所有变量,则必须调用 kwargs

然后将您的宏命名为:

{{ some_macro('some_state', **intellij) }}