I have set the dicts’ keys domain
to an empty string “”. I am checking if the var field for dict key ssluser
is defined, and if so, I then need to fill in the email domain key data extracted from that provided user value.
{%
set sslusers= [
{
'ssluser': SSL_VPN_User01,
'sslusercred': SSL_USER_CRED01,
'index': 0,
'domain': ""
},
{
'ssluser': SSL_VPN_User02,
'sslusercred': SSL_USER_CRED02,
'index': 1,
'domain': ""
},
{
'ssluser': SSL_VPN_User03,
'sslusercred': SSL_USER_CRED03,
'index': 2,
'domain': ""
},
{
'ssluser': SSL_VPN_User04,
'sslusercred': SSL_USER_CRED04,
'index': 3,
'domain': ""
},
{
'ssluser': SSL_VPN_User05,
'sslusercred': SSL_USER_CRED05,
'index': 4,
'domain': ""
},
{
'ssluser': SSL_VPN_User06,
'sslusercred': SSL_USER_CRED06,
'index': 5,
'domain': ""
},
{
'ssluser': SSL_VPN_User07,
'sslusercred': SSL_USER_CRED07,
'index': 6,
'domain': ""
},
{
'ssluser': SSL_VPN_User08,
'sslusercred': SSL_USER_CRED08,
'index': 7,
'domain': ""
},
{
'ssluser': SSL_VPN_User09,
'sslusercred': SSL_USER_CRED09,
'index': 8,
'domain': ""
},
{
'ssluser': SSL_VPN_User10,
'sslusercred': SSL_USER_CRED10,
'index': 9,
'domain': ""
}
]
%}
The jinja block am I trying to get working to do this:
{%- for item in sslusers if item.ssluser is defined %}
{% set domain_value_old = item.ssluser['domain'] %}
{% for key, value in item.items() %}
{% if key == 'domain' %}
{% set domain_value_new = value.split('@') | last %}
<update dicts in the list with the new value only for 'domain' key>
{% endif %}
{% endfor %}
{% endfor %}
I am stuck on the line under set domain_value_new...
. For context, I am using this in a cli script that is a jinja template that runs on network appliances.