Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting variable not working in Ansible

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 '@'

like image 342
MMA Avatar asked Dec 18 '25 21:12

MMA


1 Answers

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
like image 138
techraf Avatar answered Dec 21 '25 11:12

techraf