首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ansible-playbook when conditions on uri module

ansible-playbook when conditions on uri module
EN

Stack Overflow用户
提问于 2018-03-19 23:34:30
回答 1查看 2.7K关注 0票数 1

我有可供选择的攻略代码:

代码语言:javascript
复制
- name: Send file to server
  uri:
    url: "{{ url }}:{{ port }}/application/{{ item | basename }}"
    method: POST
    body: "{{ lookup('file','{{ item }}') }}"
    force_basic_auth: yes
    status_code: 201
    body_format: json
  with_fileglob: "{{ tmp_dir)_for_files }}/configs/*"
  register: code_result
  until: code_result.status == 201
  retries: "{{ uri_retries }}"
  delay: "{{ uri_delays }}"

我需要实现的是,文件将被上传到服务器,只有当不存在的时候。

EN

回答 1

Stack Overflow用户

发布于 2018-03-21 23:43:27

下面是我解决这个问题的方法

代码语言:javascript
复制
- name: Get file from server
  uri:
    url: "{{ url }}:{{ port }}/application/{{ item | basename }}"
    method: GET
    body: "{{ lookup('file','{{ item }}') }}"
    force_basic_auth: yes
    status_code: 404
    body_format: json
  with_fileglob: "{{ tmp_dir }}/configs/*"
  register: get_code_result
  ignore_errors: true

- name: Send file to server
  uri:
    url: "{{ url }}:{{ port }}/application/{{ item.item | basename }}"
    method: POST
    body: "{{ lookup('file','{{ item.item }}') }}"
    force_basic_auth: yes
    status_code: 201
    body_format: json
  with_items:
      - "{{  get_code_result.results }}"
  when: item.status == 404
  register: code_result
  until: code_result.status == 201
  retries: "{{ uri_retries }}"
  delay: "{{ uri_delays }}"

它似乎起作用了

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49366795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档