substring variables?

I can’t find anything in ansible nor jinja documentation regarding substring. I’m looking for something such as this:

`

variable passed at command line

host=prd01denutl01

{{ host | substring(0,5) }}
→ prd01

{{ host | substring(6,3) }}
→ den

{{ host | substring(9,3) }}
→ utl

`

Is there any functionality for this?

In python/jinja2 strings can be looked as lists, so host[0:5] will
give you the first 5 character substring of the string in host.

small demo play, the numbers are a bit diff than in substring, but it
works the way you want.

- hosts: localhost
  gather_facts: False
  vars:
    host: prd01denutl01
  tasks:
    - debug: msg={{ host[0:5] }}
    - debug: msg={{ host[5:8] }}
    - debug: msg={{ host[8:11] }}

ansible-playbook play.yml

Is there any functionality for this?

The variable is a Jinja2 string, so you can split it like a Python
string:

        {{ host }} -> prd01denutl01
        {{ host[0:4] }} -> prd0
        {{ host[5:7] }} -> de

        -JP

Awesome, thanks guys