Ansible:uri模块忽略状态代码

pka*_*mol 0 rest uri ansible ansible-2.x

使用以下代码迭代访问休息端点(事实上是神器):

- 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 }}"
Run Code Online (Sandbox Code Playgroud)

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

有什么建议?

tec*_*raf 6

错误的缩进.

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