Ansible - 对输出应用过滤器,然后注册为变量

8

我正在注册一个操作的输出,然后应用过滤器来显示值。但我还想将显示的值注册为变量。我无法将其注册为变量。有人知道解决方法吗?

这是我的playbook:

    ---
    - name: Filtering output to register in a variable
      hosts: localhost
      gather_facts: no
      tasks:
        - name: register filtered output to a  variable 
          uri:
            url: https://example.com/api/id
            method: GET 
            user: administrator
            password: password
            force_basic_auth: yes 
            validate_certs: no
          register: restdata
        - name: Display the output
          debug: msg="{{ restdata.json.parameter[1] }}"

我想知道,如果我们首先过滤输出,然后再将其注册为变量,是否会更简单?有人知道如何做吗?

是的,在更新版本中它得到了支持。 - sherri
1个回答

9
你无法注册一个变量,但你可以设置一个事实(在大多数情况下,包括你的情况,这与变量是等效的):
    - set_fact:
        the_output: "{{ restdata.json.parameter[1] }}"
    - name: Display the output
      debug:
        var: the_output

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接