gpt4 book ai didi

ansible - 使用 Ansible 检查 HTTP 资源的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-02 01:30:37 25 4
gpt4 key购买 nike

我正在尝试检查服务器上是否存在多个 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

检查多个资源并上传缺少的资源的正确方法是什么?

最佳答案

注册循环任务的输出时(例如使用 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

关于ansible - 使用 Ansible 检查 HTTP 资源的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34451477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com