通过调试打印可解析的子变量

  • 本文关键字:变量 调试 打印 ansible
  • 更新时间 :
  • 英文 :


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

  • 调试:var=junction_detail_ret_obj——工作在此处输入图像描述在此处输入图像描述

    "消息":{"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_cokies":"是","junction_cookie_javascript_block":"inhead","junction_hard_limit":"0-使用全局值","junction_point":"/mga","junction_soft_limit":"0-使用全局值","junction_type":"SSL","mutual_auth":"否","preserve_kokie":"否","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_port":","server_state":"正在运行","server_uuid":","total_requests":"802","虚拟连接主机名":"localhost","windows_style_url":"否"}],"session_cookie_backend_portal":"是","stateful_junction":"否","tfim_sso":"否","transparent_path_junction":"否"}}

我想打印"operation_state:Online">

- debug: msg='{{ junction_detail_ret_obj.data.servers.["operation_state"] }}'

这不起作用正在获取以下错误。

失败!=>{"msg":"模板化字符串时模板错误:需要名称或编号。字符串:{{junction_detail_ret_obj.data.servers.[\"operation_state\"]}}"}要重试,请使用:--limit@/home/pa8090/ipa_firstnet/report_junction_mga.retry

下面是一个工作剧本。试试

---
- 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') }}"
...

最新更新