Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible string concat before filter

Tags:

ansible

jinja2

I was having an issue in my Ansible template where I wanted to create an HTTP basic auth credential out of two different variables a user inputs into the play.

The first thing I tried to do was:

basic_auth: "{{ user + ':' + pass | b64encode }}"

However I ended up with:

basic_auth: "user:<BASE64_ENCODED>"

How can I have Jinja concatenate these strings and then pass it through my filter?

like image 965
Breedly Avatar asked Jul 28 '17 16:07

Breedly


1 Answers

Pretty basic solution: group with parenthesis.

basic_auth: "{{ (user + ':' + pass) | b64encode }}"

I assume that this will allow me to nest several layers of filters.

complex: "{{ ((user + ':' + pass) | b64encode) | complex_filter}}"
like image 169
Breedly Avatar answered Nov 10 '22 02:11

Breedly