2

I'm using ansible-template (Jinja2), how can i get/find a value index of a list? For example:

listvar = ['abc', 'def', 'hij']
# i want get the index of value 'hij', it should get 2

i know use for and set, is there a other simple way?

JJP
  • 825
  • 1
  • 7
  • 12
  • 1
    You can use listvar.index('hij') . Be careful when element is not present. – learner-coder Aug 15 '19 at 04:13
  • Thank you, tested success and i also try this is ok `{{ansible_play_hosts.index('not exists') if 'not exists' in ansible_play_hosts else 999 }}` – JJP Aug 15 '19 at 06:46

0 Answers0