2017-11-10 127 views
0

我正在注册一个操作的输出,然后应用过滤器来显示该值。但我也想将该显示的值注册为一个变量。我无法将其注册为变量。有谁知道这个解决方案?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] }}" 

我想知道。这难道不简单吗?如果我们先过滤输出,然后将其注册为变量?有谁知道这是怎么做到的吗 ?

+0

是,在较新的版本。它被支持。 – sherri

回答

0

不能注册一个变量,但您可以设置一个事实(这在大多数使用情况,包括你,将等同于一个变量):

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

疯狂的尊重你再次:)非常感谢你。有用。 – sherri