wharris623
wharris623

Reputation: 13

How can I parse part of a URL from an variable?

I'm trying to write a playbook that will go and download the version of ombi I supply on the command line as a variable, then parse part of it so I can rename the file and keep a local copy of it. Then gunzip then untar then stop the service overwrite the existing app, then restart the service.

I've written several other playbooks but parsing this part out has me stumped.

So if say this was the URL https://github.com/Ombi-app/Ombi/releases/download/v4.32.0/linux-x64.tar.gz

I want to extract the 4.32.0 out of that url. So my playbook run line might be something like:

ansible-playbook updateombi.yml --extra-vars "ombi_release=https://github.com/Ombi-app/Ombi/releases/download/v4.32.0/linux-x64.tar.gz"

I'm assuming I would declare a var like:

ombi_version: "{{ ombi_release | urlsplit('path') }}"

but the urlsplit is what's got me stumped. Anyone able to throw me a bone?

Upvotes: 1

Views: 355

Answers (1)

U880D
U880D

Reputation: 12083

I'm trying to write a playbook that will go and download the version of Ombi I supply on the command line as a variable ...

To do so you could simply provide the version number only

ansible-playbook updateombi.yml --extra-vars "ombi_release=4.32.0"

and construct the URL and filename afterwards within your playbook

url: "https://github.com/Ombi-app/Ombi/releases/download/v{{ ombi_release }}/linux-x64.tar.gz"
dest: /tmp/linux-x64-v{{ ombi_release }}.tar.gz

since they don't have a variable part except the version number. By doing this there would be no need for

... then parse part of it so I can rename the file ...

Upvotes: 2

Related Questions