3

I am trying to split the variable based on delimiter. How can I achieve it?

  some_module: {{item}}.split('@')[1]
  with_items:
     - git@someversionxxx
     - gradle@someversionxxx

I get following error:

list object' has no attribute 'split ansible

I want to consider only first part of variable i.e. before '@'

techraf
  • 64,883
  • 27
  • 193
  • 198
MMA
  • 408
  • 3
  • 7
  • 19

1 Answers1

10
some_module: "{{ item.split('@')[0] }}"
  • {{ ... }} is used to indicate Jinja2 expressions and everything you have is a Jinja2 expression
  • with YAML syntax in Ansible you must quote a string if it starts with { (unless it was a JSON object, here it's not)
  • the first element of the split result will have an index of 0
techraf
  • 64,883
  • 27
  • 193
  • 198