On Thursday, 23 August 2018 17.10.45 CEST Jameson wrote:
> I'm trying to write a conditional to only act on members of a list of
> strings when two characters in the string are less than a given number.
> Does anyone know if this is possible? What I'm trying now looks like:
> set_fact:
> interfaces:
> - TenGigabitEthernet 0/32
> - TenGigabitEthernet 0/33
Your set_fact is missing a dash in front
> debug: var={{ interfaces }}
> loop: "{{ facts }}"
> when: item[21:22]|int <= 32
The same does this debug.
And loop and when is indented to far in.
var= takes a variable name and not the content of one, a valid expression would be var=interfaces
Why are you using {{ facts }} it doesn't exist anywhere else in your code.
Slicing in Python is [from and including:up to but not including] so your [21:22] need to be [21:23] or just [21:] which is to the end of the line.
> When I attempt this, I get, "template error while templating string:
> expected token 'end of print statement', got 'integer'. String:
> {{TenGigabitEthernet 0/32}}"
Because of all errors you get this message.
So this should work
- set_fact:
interfaces:
- TenGigabitEthernet 0/32
- TenGigabitEthernet 0/33
- debug: var=item
loop: "{{ interfaces }}"
when: item[21:23]|int <= 32
--
Kai Stian Olstad