Setting a variable with similar values for each host

Hello

I have a group of hosts with names like this:

app01.spr.xxx.com
app02.spr.xxx.com

app10.spr.xxx.com

For each host, there’s a setting (s) that should be set like this:

s=a01
s=a02

s=a10

Since the values are similar and follow a pattern, what’s the smartest way to define them?

An obvious solution is to set a variable for each host, but i feel there’s a better way to do that.

TIA

You could do it like this in the play
- set_fact: s=a{{ inventory_hostname.split('.')[0][-2:] }}

An alternative to inventory_hostname is ansible_hostname.