2016-08-31 18 views
0

私たちは、私は、次のsnippletを実行することができた。この構造Ansible再帰的なチェックが

ゾーンスペック https://gist.github.com/git001/9230f041aaa34d22ec82eb17d444550c

を通過する必要がありますが、今、私は、エラーチェックでstuckedです。問題は、私は入口の項目を通過する必要がありますし、私がする必要があるということですansible実行の

脚本

-- 
- hosts: all 
    gather_facts: no 

    vars_files: 
    - "../doc/application-zone-spec.yml" 

    roles: 
    - { role: ingress_add, customers: "{{ application_zone_spec }}" } 

役割

- name: check if router exists 
    shell: "oc get dc -n default {{ customers.zone_name }}-{{ item.type }}" 
    with_items: "{{ customers.ingress }}" 
    ignore_errors: True 
    register: check_router 

- name: Print ingress hostnames 
    debug: var=check_router 

- name: create new router 
    shell: "echo 'I will create a router'" 
    with_items: "{{ customers.ingress }}" 
    when: check_router.rc == 1 

出力

https://gist.github.com/git001/dab97d7d12a53edfcf2a69647ad543b7

異なるタイプのエラーを "check_router" 登録。

何かのようにするといいですね。

擬似コード。

Iterate through the "customers.ingress" 
    check in "check_router" if the rc is ! 0 
    execute command. 

を使用しています。

ansible-playbook --version 
ansible-playbook 2.1.0.0 
    config file = /etc/ansible/ansible.cfg 
    configured module search path = Default w/o overrides 

答えて

0

あなたはして第二のループを置き換えることができます。これはcheck_routeループのすべてのステップを反復し、あなたがitem.itemを経由して、元のアイテムにアクセスすることができます

- name: create new router 
    shell: "echo 'I will create a router with type {{ item.item }}'" 
    with_items: "{{ check_router.results }}" 
    when: item.rc == 1 

+0

ありがとうKonstantin。これは機能します。 – Aleksandar