Ansible - How to convert list of string to list of integer?

Viewed 2684
- debug: 
    var: my_list | select("greaterthan", 2) | list
  vars: 
    my_list: 
      - "1"
      - "2"
      - "3"

Errors: '>' not supported between instances of 'str' and 'int'

I've tried my_list | int | select("greaterthan", 2) | list. But it's not works!

1 Answers

Convert the items of the list to integers. For example

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

gives

    "msg": [
        3
    ]
Related