Ansible:json过滤

Ansible:json过滤,json,ansible,jinja2,Json,Ansible,Jinja2,我会有一本从gitlab获取json的角色手册 --- - name: Make an API call uri: method: GET url: "https://gitlab.example.com/api/v4/projects/***/repository/files/Dev/raw?ref=master" headers: PRIVATE-TOKEN: ************** register: json_var

我会有一本从gitlab获取json的角色手册

---
- name: Make an API call
  uri:
    method: GET
    url: "https://gitlab.example.com/api/v4/projects/***/repository/files/Dev/raw?ref=master"
    headers:
      PRIVATE-TOKEN: **************
  register: json_var

- name: show json
  debug:
    msg: "{{json_var}}"

- name: test
  debug:
    var: json_var.json.plannedrelease
  register: release

- name: debug
  debug:
    msg: "{{ release }}"
但无法获得变量的json值,在变量发布中我只需要版本“1.0”(来自“plannedrelease”:“1.0”),如何过滤它

剧本输出为:

PLAY [127.0.0.1] ***************************************************************
TASK [Gathering Facts] *********************************************************
ok: [127.0.0.1]
TASK [get_contour_version : Make an API call] **********************************
ok: [127.0.0.1]
TASK [get_contour_version : show json] *****************************************
ok: [127.0.0.1] => {
    "msg": {
        "cache_control": "max-age=0, private, must-revalidate, no-store, no-cache", 
        "changed": false, 
        "connection": "close", 
        "content_disposition": "inline; filename=\"Dev\"; filename*=UTF-8''Dev", 
        "content_length": "402", 
        "content_type": "text/plain; charset=utf-8", 
        "cookies": {}, 
        "cookies_string": "", 
        "date": "Tue, 19 Jan 2021 19:42:33 GMT", 
        "elapsed": 0, 
        "expires": "Fri, 01 Jan 1990 00:00:00 GMT", 
        "failed": false, 
        "json": {
            "Created": "12/06/2020 10:11", 
            "Key": "123", 
            "Updated": "01/12/2020 11:51", 
            "contour": "Dev", 
            "plannedrelease": "1.0", 
            "…
TASK [get_contour_version : test] **********************************************
ok: [127.0.0.1] => {
    "json_var.json.plannedrelease": "1.0"
}
TASK [get_contour_version : debug] *********************************************
ok: [127.0.0.1] => {
    "msg": {
        "changed": false, 
        "failed": false, 
        "json_var.json.plannedrelease": "1.0"
    }
}
PLAY RECAP *********************************************************************
127.0.0.1                  : ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
可能我使用了错误的过滤方法,你试过了吗?阅读文档时,可以使用以下方法:

-名称:保存版本变量
设定事实:
发布:“{json_var.json.plannedlease}”

非常感谢,现在它工作得很好!我会尝试在这个剧本中使用set_facts,但会出现一些错误,可能是我在尝试时出现了一些语法错误