2017-06-28 7 views
0

私はサービスAPIにリクエストを提出しようとしており、後で他のコールを行う前にステータスを問い合わせています。可能性のあるネストされたループ依存

この例では、(CallOne、CallTwo)のAPIを作成しようとしていますが、どのタイプのループを探しているのですか?私はforloopをネストしようとしましたが、ループ依存関係を働かせることができませんでした。私はあなたの質問を理解して何から

- name: API - callOne 
    uri: 
    url: "https://localhost/api/commands/callOne" 
    method: POST 
    user: "admin" 
    password: "admin" 
    register: callOne 
    delegate_to: localhost 

- name: API - callOne - awating async task to complete 
    uri: 
    url: "https://localhost/api/commands/{{callOne.json['id']}}" 
    method: GET 
    user: "admin" 
    password: "admin" 
    register: callOne_repsonse 
    until: callOne_repsonse.json.active == false and callOne_repsonse.json.success == true 
    retries: 10 
    delay: 15 
    delegate_to: localhost 

- debug: msg={{callOne_repsonse.json.resultMessage}} 



- name: API - callTwo 
    uri: 
    url: "https://localhost/api/commands/callTwo" 
    method: POST 
    user: "admin" 
    password: "admin" 
    register: callTwo 
    delegate_to: localhost 

- name: API - callTwo - awating async task to complete 
    uri: 
    url: "https://localhost/api/commands/{{callTwo.json['id']}}" 
    method: GET 
    user: "admin" 
    password: "admin" 
    register: callTwo_repsonse 
    until: callTwo_repsonse.json.active == false and callTwo_repsonse.json.success == true 
    retries: 10 
    delay: 15 
    delegate_to: localhost 

- debug: msg={{callTwo_repsonse.json.resultMessage}} 
+0

それ第1の呼実行に依存する第2の呼の追加条件は何であるかは明確ではない。また、ネストされたループで試してみたが、コードに既存のループが表示されない –

答えて

1

(あなたが依存関係について話が、どれもあなたの質問に明らかにされていないとしてわからない、それはケースです)、私は解決策は、そのようなものになるだろうと思います。

- name: API - call 
    uri: 
    url: "https://localhost/api/commands/{{ item }}" 
    method: POST 
    user: "admin" 
    password: "admin" 
    register: call 
    delegate_to: localhost 
    with_items: 
    - callOne 
    - callTwo 

- name: API - awaiting async task to complete 
    uri: 
    url: "https://localhost/api/commands/{{ item.json.id }}" 
    method: GET 
    user: "admin" 
    password: "admin" 
    register: call_response 
    until: call_response.json.active == false and call_response.json.success == true 
    retries: 10 
    delay: 15 
    delegate_to: localhost 
    with_items: "{{ call.results }}" 

- debug: msg={{ item.json.resultMessage }} 
    with_items: "{{ call_response.results }}" 
関連する問題