【问题标题】:Ansible: uri module ignores status codeAnsible:uri模块忽略状态码
【发布时间】:2017-04-03 08:32:33
【问题描述】:

使用以下代码迭代地访问一个休息端点(实际上是人工制品):

- name: create local snapshots repositories
  uri:
    url: "{{ api_endpoint }}/repositories/{{ item }}-local-snapshots"
    method: PUT
    user: 'username'
    password: 'somepass'
    body: "{{ local_snapshots_repo_json|to_json }}"
    force_basic_auth: yes
    body_format: json
    return_content: yes
    status_code: 200, 400
    register: result
    changed_when: result.status == 400
  with_items: "{{ projects }}"

但是,无论我在changed_when 控件中使用什么,该任务都不会导致更改(例如changed_when == 400changed_when != 400changed_when != 'foo')。

有什么建议吗?

【问题讨论】:

    标签: rest ansible uri ansible-2.x


    【解决方案1】:

    错误的缩进。

    changed_when 是一个指令,定义为属于任务字典的键,而不是模块操作的参数。

    【讨论】:

      猜你喜欢
      • 2015-02-05
      • 2016-12-22
      • 2020-07-27
      • 2020-02-20
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      相关资源
      最近更新 更多