le9i0nx / ansible-rspamd

GNU General Public License v3.0
2 stars 1 forks source link

How to define an array? #8

Closed jasperla closed 7 years ago

jasperla commented 7 years ago

Hi,

I was wondering how one would define a structure that would end up as an array in the configuration file? Say the result should be:

    redirector_domains = [
        "${CONFDIR}/redirectors.inc:REDIRECTOR_FALSE",
        "$LOCAL_CONFDIR/local.d/redirectors.inc:LOCAL_REDIRECTOR_FALSE"
    ];

I tried this:

        redirector_domains:
          raw:
            - "${CONFDIR}/redirectors.inc:REDIRECTOR_FALSE"
            - "$LOCAL_CONFDIR/local.d/redirectors.inc:LOCAL_REDIRECTOR_FALSE"

but that results in:

    redirector_domains {
        ${CONFDIR}/redirectors.inc:REDIRECTOR_FALSE
        $LOCAL_CONFDIR/local.d/redirectors.inc:LOCAL_REDIRECTOR_FALSE
    }

Which doesn't seem to be equivalent.

le9i0nx commented 7 years ago

hi. If I understood correctly then you need.

The parentheses that are obtained are predefined in the file https://github.com/le9i0nx/ansible-rspamd/blob/master/templates/etc/rspamd/conf.d/default.conf.j2#L5

You need to create a new file with an arbitrary name in the folder templates/etc/rspamd/conf.d

With something like this

#{{ ansible_managed }}
{%  if item.data is mapping %}
{%    for key, value in item.data|dictsort %}
{%      set tabs = [] %}
{%      for i in tabs %}{{i}}{% endfor %}{{ key }} = [
{%      include 'nested_structure.j2' %}
{%      for i in tabs %}{{i}}{% endfor %}]
{%    endfor %}
{%  endif %}

and

rspamd__conf_d:

  - name: "redirector_domains"
    type: "arbitrary name"
    data:
        redirector_domains:        
          raw:
            - "${CONFDIR}/redirectors.inc:REDIRECTOR_FALSE"
            - "$LOCAL_CONFDIR/local.d/redirectors.inc:LOCAL_REDIRECTOR_FALSE"

https://github.com/le9i0nx/ansible-rspamd/blob/master/tasks/config.yml#L15

le9i0nx commented 7 years ago

It is possible so still

rspamd__conf_d:

  - name: "redirector_domains"
    data:
        phishing:
           raw:
             - 'redirector_domains = ['
             - '  "${CONFDIR}/redirectors.inc:REDIRECTOR_FALSE",'
             - '  "$LOCAL_CONFDIR/local.d/redirectors.inc:LOCAL_REDIRECTOR_FALSE"'
             - '];'
jasperla commented 7 years ago

Thanks! This did the trick for me:

  - name: phishing
    data:
      phising:
        symbol: PHISHING
        openphish_enabled: yes
        raw:
          - 'redirector_domains = ['
          - '  "${CONFDIR}/redirectors.inc:REDIRECTOR_FALSE"'
          - '  "$LOCAL_CONFDIR/local.d/redirectors.inc:LOCAL_REDIRECTOR_FALSE"'
          - '];'