1

I have got a debug msg in ansible in the below format:

"msg": [ "Output: test output ", "ABC: some text ", "", "Master ", "Location: test location ", "URL: https://www.google.com " ] 

}

Now I want to retrieve the URL value from the above output, which i will use in rest of the ansible script. How can i get this URL which is "http://www.google.com", in this exact format? Please help.

1 Answer 1

1

Q: "How can I get this URL which is "http://www.google.com", in this exact format?"

A: Create a dictionary. Given the list

 my_list: ["Output: test output ", "ABC: some text ", "", "Master ", "Location: test location ", "URL: https://www.google.com "] 

The task

 - set_fact: my_dict: "{{ my_dict|default({})|combine(item|from_yaml) }}" loop: "{{ my_list }}" when: item|from_yaml is mapping 

creates the dictionary

 my_dict: ABC: some text Location: test location Output: test output URL: https://www.google.com 

Get the attribute URL

 - debug: var: my_dict.URL 

gives

 my_dict.URL: https://www.google.com 
1
  • 1
    Thanks so much. Works perfectly. Commented Mar 2, 2021 at 14:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.