regex_replace filter

64 views
Skip to first unread message

Sri Krishna G

unread,
Apr 6, 2019, 3:33:34 PM4/6/19
to Ansible Project
I have a list of strings like :
 
[hosts]
10.100.0.1
10.100.0.2
10.100.0.3

I am following the example under : https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html to "add "https://" prefix to each item in a list"
In my case I am appending the port number at the end of every item in the list and joining them with a "," to get a string at the end. I am expecting to see something like:

10.100.0.1:2181,10.100.0.2:2181,10.100.0.3:2181

I am creating a variable as:

zookeeper_masters: "{{'zk://' + hosts | map('regex_replace', '^(.*)$', '\\1:2181') | join(',')}}"


My result comes as:
"zk://10.100.0.1:2181:2181,10.100.0.2:2181:2181,10.100.0.3:2181:2181"

Can some one point out as to why I am getting the port number twice?

Sri Krishna G

unread,
Apr 7, 2019, 1:13:32 AM4/7/19
to Ansible Project
Please ignore this issue. It was a mistake in the next part of the play book that is causing the port to come twice. 
Reply all
Reply to author
Forward
0 new messages