剧本中的Ansible递归检查 [英] Ansible recursive checks in playbooks
本文介绍了剧本中的Ansible递归检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们需要经历这个结构
区域规格 https://gist.github.com/git001/9230f041aaa34d22ec82eb17d444550c
我能够运行以下代码段,但现在我陷入了错误检查的境地.
I was able to run the following snipplet but now I'm stucked at the error checking.
剧本
--
- 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"寄存器映射不同类型的错误.
The problem is that I need to go through the ingress items and I need to map the error of the differnt types from the "check_router" register.
做类似的事情会很好.
伪代码.
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
推荐答案
您可以将第二个循环替换为:
You can replace the second loop with:
- name: create new router
shell: "echo 'I will create a router with type {{ item.item }}'"
with_items: "{{ check_router.results }}"
when: item.rc == 1
这将遍历check_route
循环的每个步骤,您可以通过item.item
访问原始项目.
This will iterate over every step of check_route
loop and you can access original items via item.item
.
这篇关于剧本中的Ansible递归检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文