2017-11-10 125 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