我正在尝试检查服务器上是否存在多个HTTP资源,以及他们何时不想上传它们。问题是我不知道如何注册多个
- name: Checking if schema already exists
uri:
url: http://{{ riak_server }}:10018/search/schema/{{ item }} return_content=yes
register: http_response_{{ item }}
failed_when: http_response_{{ item }}.status != 400
with_items:
- sch_patents
- sch_entities
- sch_cpcs
- sch_ipcs
- sch_entities_patents
run_once: true
delegate_to: "{{ riak_server }}"
tags: creating_schema
调用任务失败:
TASK: [riak | Checking if schema already exists] ******************************
fatal: [10.10.10.11 -> 10.10.10.11] => error while evaluating conditional: http_response_sch_patents.status != 400
FATAL: all hosts have already failed -- aborting
检查多个资源并上传丢失的资源的正确方法是什么?
答案 0 :(得分:2)
当从循环任务中注册输出时(例如使用with_items
时),您将从所有循环变量中获得响应的字典。
所以你应该做这样的事情:
- name: Checking if schema already exists
uri:
url: http://{{ riak_server }}:10018/search/schema/{{ item }} return_content=yes
register: http_responses
with_items:
- sch_patents
- sch_entities
- sch_cpcs
- sch_ipcs
- sch_entities_patents
run_once: true
delegate_to: "{{ riak_server }}"
tags: creating_schema
- name: copy schema if not exists
copy:
src: path/to/src/schema
dest: path/to/dest/
when: {{ item.status }} != 400
with_items: http_responses.results