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



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

这是我的剧本

    ---
    - 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] }}"

我纳闷。不是更简单吗?如果我们先过滤输出,然后将其注册为变量?有谁知道该怎么做?

您不能注册变量,但可以设置一个事实(在大多数用例中,包括您的用例,将等效于变量(:

    - set_fact:
        the_output: "{{ restdata.json.parameter[1] }}"
    - name: Display the output
      debug:
        var: the_output

相关内容

最新更新