Hello Everyone,
When I use the regex_search in tasks, it is adding single quotes in the starting and end.
Like for this -
- sw01 GigabitEthernet0/0 IF-MIB.ifSpeed = 1000000000
when I use regex_search-
- name: SET FACT - Interface SPEED -1
set_fact:
speeds: "{{ item.0 | regex_search('[^=]*$') | regex_replace(' ', '') }}"
Converting above value to -
ok: [localhost] => (item=['sw01 GigabitEthernet0/0 IF-MIB.ifSpeed = 1000000000'])
My goal is fetch the value after '='
sw01 GigabitEthernet0/0 IF-MIB.ifSpeed = 1000000000
to
1000000000
please advise.
The regex_search filter is superfluous in this case, try:
regex_replace('^.*=(.*)$', '\\1')
\\1 references the part of the string matched by (.*).
Thank you so much, Racke.
It worked like a charm. I was using it with rest API in JSON format. When I debug, it was adding single quotes(‘) but when I passed the command in URI module as you advised, it was not adding single quotes (’).