首页 > 解决方案 > status_code 的状态码范围

问题描述

Ansible 2.9.6

当我将状态代码指定为 list时,剧本运行良好。

---
- hosts: localhost
  tasks:
    - name: Create a new bitbucket repository
      uri:
        user: "{{username}}"
        password: "{{password}}"
        method: POST
        body_format: json
        body: "{{ lookup('file','create-repo.json')}}"
        return_content: yes
        status_code: [200,201,400,401,403,409,500]
        force_basic_auth: yes
        validate_certs: no
        url: "{{url}}"
      register: bitbucketResponse

    - name: show bitbucket reponse
      debug:
        msg: "{{bitbucketResponse}}"
...

我希望指定一个范围(200 到 500),但我不知道它是否受支持,例如:status_code: [200:500]

标签: ansibleansible-2.x

解决方案


可以使用range。例如

    status_code: "{{ range(200, 500, 1)|list }}"

推荐阅读