通过调试打印Ansible子变量

通过调试打印Ansible子变量,ansible,Ansible,我试图通过调试语句打印子变量 调试:var=junction\u detail\u ret\u obj——工作 “味精”:{ “活动线程”:“0”, “授权规则”:“否”, “基本授权模式”:“忽略”, “布尔规则头”:“否”, “客户端\u ip\u http”:“插入”, “cookie\u include\u路径”:“否”, “授权支持”:“否”, “基于表单的单点登录”:“已禁用”, “fsso_配置_文件”:“已禁用”, “http_header_ident”:“”, “插入会话\

我试图通过调试语句打印子变量

  • 调试:var=junction\u detail\u ret\u obj——工作

    “味精”:{ “活动线程”:“0”, “授权规则”:“否”, “基本授权模式”:“忽略”, “布尔规则头”:“否”, “客户端\u ip\u http”:“插入”, “cookie\u include\u路径”:“否”, “授权支持”:“否”, “基于表单的单点登录”:“已禁用”, “fsso_配置_文件”:“已禁用”, “http_header_ident”:“”, “插入会话\u cookies”:“是”, “连接\u cookie\u javascript\u块”:“inhead”, “交叉点硬限制”:“0-使用全局值”, “交叉点”:“/mga”, “交叉点软限制”:“0-使用全局值”, “连接类型”:“SSL”, “相互授权”:“否”, “保留饼干”:“否”, “远程\u http\u头”:“”, “请求_编码”:“”, “脚本编写支持”:“是”, “服务器”:[ { “区分大小写的url”:“否”, “当前_请求”:“0”, “http_端口”:“”, “本地知识产权”:“, “运行状态”:“在线” “查询内容url”:“”, “查询内容”:“未知”, “服务器dn”:“”, “服务器主机名”:“”, “服务器\u端口”:“”, “服务器状态”:“正在运行”, “服务器\u uuid”:“”, “请求总数”:“802”, “虚拟主机名”:“本地主机”, “windows\u样式\u url”:“否” } ], “会话\u cookie\u后端\u门户”:“是”, “有状态连接”:“否”, “tfim_sso”:“否”, “透明路径连接”:“否” } }

我想打印“操作状态:在线”

出现以下错误时,此操作不起作用

失败!=>{“msg”:“模板字符串时模板错误:应为名称或编号。字符串:{{{junction\u detail\u ret\u obj.data.servers.[\'operation\u state\']}”
要重试,请使用:--limit@/home/pa8090/ipa\u firstnet/report\u junction\u mga。重试

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

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

json中没有名为
data
的键。您应该查询的是
junction\u detail\u ret\u obj.servers[0]。操作状态
---
- 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') }}"
...