This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Jinja2 template issue with mistral server

I have a mistral action that has the following input parameters:

    input:
      cmts_hostname: '<% $.cmts.cmts %>'
      mac_list:
        CM_MAC_ADDRS: '{% set macs=[] %}{% for mac in _.cmts.mac -%}{{ macs.append({"CM_MAC_ADDR": mac,"ACTION":"UNBLOCK", "REASON": "AGING"}) }}{%- endfor %}{{ macs }}'

however the log file shows additional “None” string in the data structure:

2019-06-21 03:14:01.110 260 INFO mistral.notifiers.notification_server [req-83f261a9-ddd4-4c73-862f-777a17292759 - - - - -] Received RPC request ‘notify’[ex_id=aa87eb30-eca0-44bd-a4c6-cd85f22240cb, event=TASK_LAUNCHED, timestamp=None, data={u’state_info’: None, u’in_context’: {u’__task_execution’: {u’id’: u’aa87eb30-eca0-44bd-a4c6-cd85f22240cb’, u’name’: u’unblock_cmts’}}, u’name’: u’unblock_cmts’, u’workflow_name’: u’modem_clone.unblock_aged_modems_workflow.unblock_cmts’, u’unique_key’: None, u’created_at’: u’2019-06-21 03:14:01’, u’runtime_context’: {}, u’state’: u’RUNNING’, u’id’: u’aa87eb30-eca0-44bd-a4c6-cd85f22240cb’, u’workflow_execution_id’: u’5d96372b-edfb-4720-8515-2c352a2e698d’, u’workflow_id’: u’6141d78c-79bd-449b-ae47-57e58b9feac2’, u’workflow_namespace’: u’’, u’published’: {}, u’scope’: u’private’, u’project_id’: u’’, u’type’: u’ACTION’, u’spec’: {u’action’: u’st2.action’, u’input’: {u’ref’: u’modem_clone.modify_modem_block_list_workflow’, u’parameters’: {u’cmts_hostname’: u’<% .cmts.cmts %>', u'mac_list': {u'CM_MAC_ADDRS': u'{% set macs=[] %}{% for mac in _.cmts.mac -%}{{ macs.append({"CM_MAC_ADDR": mac,"ACTION":"UNBLOCK", "REASON": "AGING"}) }}{%- endfor %}{{ macs }}'}, u'run_id': u'<% .run_id %>’}}, u’version’: u’2.0’, u’type’: u’direct’, u’name’: u’unblock_cmts’}, u’processed’: False}, publishers=[{u’type’: u’st2’}]]
2019-06-21 03:14:01.111 260 INFO st2mistral.notifiers.stackstorm_notifier [req-83f261a9-ddd4-4c73-862f-777a17292759 - - - - -] The event TASK_LAUNCHED for aa87eb30-eca0-44bd-a4c6-cd85f22240cb is not processed for st2 because there is no event handler defined.
2019-06-21 03:14:01.137 260 INFO mistral.executors.executor_server [req-3a2ab8a5-d7f6-491e-b389-6947d8bd7d7a - - - - -] Received RPC request ‘run_action’[action_ex_id=700907b8-42cf-49c0-95df-5875393488b1, action_cls_str=st2mistral.actions.stackstorm.St2Action, action_cls_attrs={}, params={st2_context: {u’endpoint’: u’http://127.0.0.1:9101/v1/actionexecutions’, u’api_url’: u’http://127.0.0.1:9101/v1’, u’parent’: {u’trace_context’: {}, u’user’: u’admin’, u’execution_id’: u’5d0c4b776ee06301ddd02959’, u’pack’: u’modem_clone’}, u’auth_token’: u’4d02c6396d934626b1df739a973c3880’, u’notify’: {}, u’skip_notify_tasks’: []}…, timeout=None]
2019-06-21 03:14:01.145 260 INFO st2mistral.actions.stackstorm [req-3a2ab8a5-d7f6-491e-b389-6947d8bd7d7a - - - - -] Running St2Action [action_context={‘action_execution_id’: u’700907b8-42cf-49c0-95df-5875393488b1’, ‘workflow_name’: u’modem_clone.unblock_aged_modems_workflow.unblock_cmts’, ‘task_execution_id’: u’aa87eb30-eca0-44bd-a4c6-cd85f22240cb’, ‘workflow_execution_id’: u’5d96372b-edfb-4720-8515-2c352a2e698d’, ‘task_name’: u’unblock_cmts’, ‘callback_url’: u’/v2/action_executions/700907b8-42cf-49c0-95df-5875393488b1’}, ref=modem_clone.modify_modem_block_list_workflow, parameters={u’cmts_hostname’: u’nxs01chdcnc’, u’mac_list’: {u’CM_MAC_ADDRS’: u"None[{‘ACTION’: ‘UNBLOCK’, ‘CM_MAC_ADDR’: u’08:00:27:ef:f6:50’, ‘REASON’: ‘AGING’}]"}, u’run_id’: u’cc6e68427afc’}, st2_context={u’endpoint’: u’http://127.0.0.1:9101/v1/actionexecutions’, u’api_url’: u’http://127.0.0.1:9101/v1’, u’parent’: {u’trace_context’: {}, u’user’: u’admin’, u’execution_id’: u’5d0c4b776ee06301ddd02959’, u’pack’: u’modem_clone’}, u’skip_notify_tasks’: [], u’notify’: {}}]
2019-06-21 03:14:01.145 260 INFO st2mistral.actions.stackstorm [req-3a2ab8a5-d7f6-491e-b389-6947d8bd7d7a - - - - -] Sending HTTP request for St2Action [action_context={‘action_execution_id’: u’700907b8-42cf-49c0-95df-5875393488b1’, ‘workflow_name’: u’modem_clone.unblock_aged_modems_workflow.unblock_cmts’, ‘task_execution_id’: u’aa87eb30-eca0-44bd-a4c6-cd85f22240cb’, ‘workflow_execution_id’: u’5d96372b-edfb-4720-8515-2c352a2e698d’, ‘task_name’: u’unblock_cmts’, ‘callback_url’: u’/v2/action_executions/700907b8-42cf-49c0-95df-5875393488b1’}, ref=modem_clone.modify_modem_block_list_workflow, parameters={u’cmts_hostname’: u’nxs01chdcnc’, u’mac_list’: {u’CM_MAC_ADDRS’: u"None[{‘ACTION’: ‘UNBLOCK’, ‘CM_MAC_ADDR’: u’08:00:27:ef:f6:50’, ‘REASON’: ‘AGING’}]"}, u’run_id’: u’cc6e68427afc’}, st2_context={u’endpoint’: u’http://127.0.0.1:9101/v1/actionexecutions’, u’api_url’: u’http://127.0.0.1:9101/v1’, u’parent’: {u’trace_context’: {}, u’user’: u’admin’, u’execution_id’: u’5d0c4b776ee06301ddd02959’, u’pack’: u’modem_clone’}, u’skip_notify_tasks’: [], u’notify’: {}}]
2019-06-21 03:14:01.253 260 INFO st2mistral.actions.stackstorm [req-3a2ab8a5-d7f6-491e-b389-6947d8bd7d7a - - - - -] Received HTTP response for St2Action [action_context={‘action_execution_id’: u’700907b8-42cf-49c0-95df-5875393488b1’, ‘workflow_name’: u’modem_clone.unblock_aged_modems_workflow.unblock_cmts’, ‘task_execution_id’: u’aa87eb30-eca0-44bd-a4c6-cd85f22240cb’, ‘workflow_execution_id’: u’5d96372b-edfb-4720-8515-2c352a2e698d’, ‘task_name’: u’unblock_cmts’, ‘callback_url’: u’/v2/action_executions/700907b8-42cf-49c0-95df-5875393488b1’}, ref=modem_clone.modify_modem_block_list_workflow, parameters={u’cmts_hostname’: u’nxs01chdcnc’, u’mac_list’: {u’CM_MAC_ADDRS’: u"None[{‘ACTION’: ‘UNBLOCK’, ‘CM_MAC_ADDR’: u’08:00:27:ef:f6:50’, ‘REASON’: ‘AGING’}]"}, u’run_id’: u’cc6e68427afc’}, st2_context={u’endpoint’: u’http://127.0.0.1:9101/v1/actionexecutions’, u’api_url’: u’http://127.0.0.1:9101/v1’, u’parent’: {u’trace_context’: {}, u’user’: u’admin’, u’execution_id’: u’5d0c4b776ee06301ddd02959’, u’pack’: u’modem_clone’}, u’skip_notify_tasks’: [], u’notify’: {}}]:
201
{
“status”: “requested”,
“start_timestamp”: “2019-06-21T03:14:01.174440Z”,
“log”: [
{
“status”: “requested”,
“timestamp”: “2019-06-21T03:14:01.000000Z”
}
],
“parameters”: {
“cmts_hostname”: “nxs01chdcnc”,
“mac_list”: {
“CM_MAC_ADDRS”: “None[{‘ACTION’: ‘UNBLOCK’, ‘CM_MAC_ADDR’: u’08:00:27:ef:f6:50’, ‘REASON’: ‘AGING’}]”
},

I compared jinja2 version between ansible and st2, but are on 2.10, but ansible is fine with the above template, but not st2.

I changed to YAQL which is much clean and has no issue:

   input:
      cmts_hostname: '<% $.cmts.cmts %>'
      mac_list:
        CM_MAC_ADDRS: '<% $.cmts.mac.select({"CM_MAC_ADDR"=> $, "ACTION"=>"UNBLOCK", "REASON"=>"AGING"}) %>'
2 Likes