剧本中的 Ansible 递归检查 [英] Ansible recursive checks in playbooks
问题描述
我们需要通过这个结构
区域规格https://gist.github.com/git001/9230f041aaa34d22ec82eb17d44444 我能够运行以下代码片段,但现在我被困在错误检查中. 剧本 角色 ansible 运行的输出 https://gist.github.com/git001/dab97d7d12a53edfcf2a693647ad 问题是我需要通过入口项目,我需要从check_router"寄存器映射不同类型的错误. 制作类似的东西会很好. 伪代码. 我们使用. 您可以将第二个循环替换为: 这将遍历 We need to go through this structure Zone spec
https://gist.github.com/git001/9230f041aaa34d22ec82eb17d444550c I was able to run the following snipplet but now I'm stucked at the error checking. playbook role Output of a ansible run https://gist.github.com/git001/dab97d7d12a53edfcf2a69647ad543b7 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. It would be nice to make something like. Pseudo code. We use.
You can replace the second loop with: This will iterate over every step of 这篇关于剧本中的 Ansible 递归检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!--- 主持人:所有收集事实:没有vars_files:- ../doc/application-zone-spec.yml"角色:- { 角色:ingress_add,客户:{{ application_zone_spec }}" }
- name:检查路由器是否存在shell: "oc get dc -n default {{customers.zone_name }}-{{ item.type }}"with_items: "{{customers.ingress }}"ignore_errors: 真注册:check_router- name:打印入口主机名调试:var=check_router- 名称:创建新路由器shell: "echo '我将创建一个路由器'"with_items: "{{customers.ingress }}"时间:check_router.rc == 1
遍历customers.ingress"如果 rc 是,请检查check_router"!0执行命令.
ansible-playbook --versionansible-剧本 2.1.0.0配置文件 =/etc/ansible/ansible.cfg配置的模块搜索路径 = 默认无覆盖
- 名称:创建新路由器shell:echo '我将创建一个类型为 {{ item.item }}' 的路由器"with_items: "{{ check_router.results }}"什么时候: item.rc == 1
check_route
循环的每一步,您可以通过 item.item
访问原始项目.--
- 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
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
- 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
loop and you can access original items via item.item
.