如何将字符串列表转换为整数列表?

The*_*kda 3 jinja2 ansible

- debug: 
    var: my_list | select("greaterthan", 2) | list
  vars: 
    my_list: 
      - "1"
      - "2"
      - "3"
Run Code Online (Sandbox Code Playgroud)

错误:'>' not supported between instances of 'str' and 'int'

我已经尝试过my_list | int | select("greaterthan", 2) | list,但没有给出预期的结果。

Vla*_*tka 9

将列表的项目转换为整数。例如

    - debug:
        msg: "{{ my_list|map('int')|select('greaterthan', 2)|list }}"
      vars:
        my_list:
          - "1"
          - "2"
          - "3"
Run Code Online (Sandbox Code Playgroud)

给出

    "msg": [
        3
    ]
Run Code Online (Sandbox Code Playgroud)