I have a python script that in summary outputs only one line, a long URL. example: https://www.google.com/ . Now, after I execute the python script WITHIN ansible, i try to register the output to a variable, and then proceed to use get_url module to download the file from the URL.
- name: get url from python code
script: get_url.py
register: output
- debug: var=output
- name: Use URL to download file
get_url:
url: "((output}}"
dest: "/path/example/"
However, I get this error: Request failed: <urlopen error unknown url type It seems that the result is still being output as stdout: 'https....'
How do i grab the exact URL from that python output and use ansible get_url to download it ? The python result is only one line, and that is only the URL, nothing else.
Considering that the URL returned in
stdout_linesis a list (denoted by[]), we can access it with the first element[0], i.e.output.stdout_lines[0].Then the
get_urltask should use the same URL:Note that this based on an assumption that the Python script returns only 1 URL. You could also use
url: "{{ output.stdout }}"in that case.