Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace character in a string with Ansible

Tags:

I have this Ansible as a String:

FUBAR={{ PREFIX }}_{{ CNAME }}{{ VERSION }}

I want to replace all . in the concatenated string with '', like this:

FUBAR={{ {{ PREFIX }}_{{ CNAME }}{{ VERSION }} | replace('.','') }}

I get the message:

expected token ':', got '}'

Could anyone give me a suggestion what's wrong?

like image 203
s_bei Avatar asked Dec 07 '18 13:12

s_bei


1 Answers

FUBAR="{{ ( PREFIX + '_' + CNAME + VERSION ) | replace('.','') }}"

Resolving a few problems:

  • too many '{{}}'s
  • need quotes around the whole expression
  • the replace will only act on the last element unless it is all surrounded by '()'s
like image 185
clockworknet Avatar answered Sep 26 '22 08:09

clockworknet