通过调试打印Ansible子变量

时间:2018-11-29 17:13:56

标签: ansible

我正在尝试通过Debug语句打印子变量。

  • 调试:var = junction_detail_ret_obj-工作 enter image description here enter image description here

    “ msg”:{         “ active_worker_threads”:“ 0”,         “ authz_rules”:“否”,         “ basic_auth_mode”:“忽略”,         “ boolean_rule_header”:“否”,         “ client_ip_http”:“插入”,         “ cookie_include_path”:“否”,         “ delegation_support”:“否”,         “ forms_based_sso”:“已禁用”,         “ fsso_config_file”:“已禁用”,         “ http_header_ident”:“”,         “ insert_session_cookies”:“是”,         “ junction_cookie_javascript_block”:“内部”,         “ junction_hard_limit”:“ 0-使用全局值”,         “ junction_point”:“ / mga”,         “ junction_soft_limit”:“ 0-使用全局值”,         “ junction_type”:“ SSL”,         “ mutual_auth”:“否”,         “ preserve_cookie”:“否”,         “ remote_http_header”:“”,         “ request_encoding”:“”,         “ scripting_support”:“是”,         “服务器”:[             {                 “ case_sensitive_url”:“否”,                 “ current_requests”:“ 0”,                 “ http_port”:“”,                 “ local_ip”:“”,                  “ operation_state”:“在线”,                 “ query_content_url”:“”,                 “ query_contents”:“未知”,                 “ server_dn”:“”,                 “ server_hostname”:“”,                 “服务器端口”: ””,                 “ server_state”:“正在运行”,                 “ server_uuid”:“”,                 “ total_requests”:“ 802”,                 “ virtual_junction_hostname”:“本地主机”,                 “ windows_style_url”:“否”             }         ],         “ session_cookie_backend_portal”:“是”,         “ stateful_junction”:“否”,         “ tfim_sso”:“否”,         “ transparent_path_junction”:“否”     } }

我要打印“ operation_state:在线”

SELECT
  event_date,
  event_name,
  COUNT(DISTINCT user_pseudo_id) as userPseudoId, 
  COUNT(event_name) as eventNameCount
FROM `project.analytics_XXXXXXXXX.events_*`, UNNEST(event_params) as eventparams
WHERE _TABLE_SUFFIX >= '20180601'
  AND platform = "ANDROID"
  AND event_name = "in_app_purchase"
  AND user_pseudo_id IN (
    SELECT user_pseudo_id
    FROM `project.analytics_XXXXXXXXX.events_*`, UNNEST(event_params) as eventparams
    WHERE _TABLE_SUFFIX >= '20180601'
    AND user_first_touch_timestamp >= 1541808000000000 AND user_first_touch_timestamp < 1541894400000000 
    AND platform = "ANDROID"
    AND event_name = "ABTest"
    AND eventparams.key = "Group"
    AND eventparams.value.string_value LIKE "variation_A"
    GROUP BY 1)
GROUP BY 1,2

这不起作用。出现以下错误。

失败! => {“ msg”:“模板字符串时出现模板错误:预期名称或数字。字符串:{{junction_detail_ret_obj.data.servers。[\” operation_state \“]}}”“}         要重试,请使用:--limit @ / home / pa8090 / ipa_firstnet / report_junction_mga.retry

1 个答案:

答案 0 :(得分:1)

以下是一部作品。试试吧

---
- name: Json query play
  hosts: 127.0.0.1
  connection: local
  tasks:
    #This task sets the fact about pool-names and creates a list var.
    - name: Set junction_detail_ret_obj fact
      set_fact:
        junction_detail_ret_obj: '{ "active_worker_threads": "0", "authz_rules": "no", "basic_auth_mode": "ignore", "boolean_rule_header": "no", "client_ip_http": "insert", "cookie_include_path": "no", "delegation_support": "no", "forms_based_sso": "disabled", "fsso_config_file": "disabled", "http_header_ident": "", "insert_session_cookies": "yes", "junction_cookie_javascript_block": "inhead", "junction_hard_limit": "0 - using global value", "junction_point": "/mga", "junction_soft_limit": "0 - using global value", "junction_type": "SSL", "mutual_auth": "no", "preserve_cookie": "no", "remote_http_header": "", "request_encoding": "", "scripting_support": "yes", "servers": [ { "case_sensitive_url": "no", "current_requests": "0", "http_port": "", "local_ip": "", "operation_state": "Online", "query_content_url": "", "query_contents": "unknown", "server_dn": "", "server_hostname": "", "server_port": "", "server_state": "running", "server_uuid": "", "total_requests": "802", "virtual_junction_hostname": "localhost", "windows_style_url": "no" } ], "session_cookie_backend_portal": "yes", "stateful_junction": "no", "tfim_sso": "no", "transparent_path_junction": "no" }'

    - name: Debug print operation state
      debug:
        msg: "operation_state:{{ junction_detail_ret_obj | from_json | json_query('servers[0].operation_state') }}"
...