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


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/109654460.0pOxjzcbZN%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply via email to