ansible.builtin.urlsplit filter – get components from URL

Note

This filter plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name urlsplit even without specifying the collections: keyword. However, we recommend you use the FQCN for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.

New in Ansible 2.4

Synopsis

  • Split a URL into its component parts.

Input

This describes the input of the filter, the value before | ansible.builtin.urlsplit.

Parameter

Comments

Input

string / required

URL string to split.

Positional parameters

This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | ansible.builtin.urlsplit(positional1, positional2, ...).

Parameter

Comments

query

string

Specify a single component to return.

Choices:

  • "fragment"

  • "hostname"

  • "netloc"

  • "password"

  • "path"

  • "port"

  • "query"

  • "scheme"

  • "username"

Examples

parts: '{{ "http://user:[email protected]:9000/dir/index.html?query=term#fragment" | urlsplit }}'
# =>
#   {
#       "fragment": "fragment",
#       "hostname": "www.acme.com",
#       "netloc": "user:[email protected]:9000",
#       "password": "password",
#       "path": "/dir/index.html",
#       "port": 9000,
#       "query": "query=term",
#       "scheme": "http",
#       "username": "user"
#   }

hostname: '{{ "http://user:[email protected]:9000/dir/index.html?query=term#fragment" | urlsplit("hostname") }}'
# => 'www.acme.com'

query: '{{ "http://user:[email protected]:9000/dir/index.html?query=term#fragment" | urlsplit("query") }}'
# => 'query=term'

path: '{{ "http://user:[email protected]:9000/dir/index.html?query=term#fragment" | urlsplit("path") }}'
# => '/dir/index.html'

Return Value

Key

Description

Return value

any

A dictionary with components as keyword and their value.

If query is provided, a string or integer will be returned instead, depending on query.

Returned: success

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.