Hello Developer Community!
I'm currently working on developing some Ansible playbooks to manage Citrix NetScaler configuration and would like to get some help about the following. I have the following data structure defined in a variable file:
nsadc_config_file_textfsm_nsapp_lb_service_parsed
{
"bind_lbvserver_NotParsed": "",
"bind_lbvserver_analyticsprofile": "",
"bind_lbvserver_gotopriorityexpression": "",
"bind_lbvserver_name": "VSRV-CS-Client1",
"bind_lbvserver_policyname": "",
"bind_lbvserver_priority": "",
"bind_lbvserver_service_group_name": "SVC_Client1_App1_Server1_Port1",
"bind_lbvserver_type": "",
"bind_lbvserver_weight": ""
},
{
"bind_lbvserver_NotParsed": "",
"bind_lbvserver_analyticsprofile": "",
"bind_lbvserver_gotopriorityexpression": "NEXT",
"bind_lbvserver_name": "VSRV_Client2_App2",
"bind_lbvserver_policyname": "policy_Client2_Rewrite",
"bind_lbvserver_priority": "80",
"bind_lbvserver_service_group_name": "",
"bind_lbvserver_type": "REQUEST",
"bind_lbvserver_weight": ""
},
I would like to query this JSON structure in a Jinja file, tried the followings but unfortunately it does not work. I'm not 100% sure if it is possible to use "json_query" in a Jinja file.
servicebindings:
{% for item_1 in nsadc_config_file_textfsm_nsapp_lb_vserver_binding_parsed %}
{% if (item_0.add_lbvserver_name == item_1.bind_lbvserver_name) and (item_1.bind_lbvserver_service_group_name in nsadc_config_file_textfsm_nsapp_lb_service_parsed) %}
- servicename: "{{ item_1.bind_lbvserver_service_group_name }}"
{% if item_1.bind_lbvserver_weight is defined and item_1.bind_lbvserver_weight %}
weight: "{{ item_1.bind_lbvserver_weight }}"
{% endif %}
{% endif %}
{% endfor %}
Instead of using (item_1.bind_lbvserver_service_group_name in nsadc_config_file_textfsm_nsapp_lb_service_parsed)
above, I have also tried to include a json_query statement directly in Jinja, but with no luck. I'm afraid, there might be an issue with using quotes and escape chars.
{% if (item_0.add_lbvserver_name == item_1.bind_lbvserver_name) and (nsadc_config_file_textfsm_nsapp_lb_service_parsed | json_query(\"[?add_svc_name == '\" + item_1.bind_lbvserver_service_group_name + \"']\")) %}
Could anybody please advise if it is possible to query JSON structure directly in Jinja?
Many thanks in advance!