0

I am trying to run below code and able to get the SID which will be passed to the URL but not sure why it is adding dash when I try to get the SID value using below code. I need to pass just the value to the URL.

Its basically about how to convert the dictionary item to a string, not sure how to do :|

- set_fact: 
    regexp1: '\"sid"\: \"([^"]+)'

- set_fact: 
    ssid: "{{ dict | selectattr('Details','contains',item) | to_nice_json | regex_search(regexp1,'\\1')}}"

- debug: msg="{{ssid}}"

Output

msg:
  - 01234567899

sid: 01234567899 is the line I have in my dict.

It is passing the SID enclosed in square brackets with single quotes.

https://abc.service-now.com/api/now/table/sc_task/['01234567899']

I am expecting to see

https://abc.service-now.com/api/now/table/sc_task/01234567899
U880D
  • 8,601
  • 6
  • 24
  • 40
user312307
  • 153
  • 6
  • 21

1 Answers1

0

As already mentioned in the comments, the output is a list with one element counted from zero (0), a single element array.

To get a better insight into the variable type you may use according Managing data type - Discovering the data type type_debug.

- debug: 
    msg: "{{ ssid }} of type {{ ssid | type_debug }}"

For further processing you may access the list element by position like ssid[0] or use an other Templating (Jinja2) filter like join to convert the list to string.

Further Q&A

U880D
  • 8,601
  • 6
  • 24
  • 40