Skip to content

urlsplit

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 2.4.

Synopsis

  • Split a URL into its component parts.

Parameters

Parameter Defaults / Choices Comments
_input
str
required
URL string to split.
query
str
Choices: fragment, hostname, netloc, password, path, port, query, scheme, username Specify a single component to return.

Examples

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

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

    query: '{{ "http://user:password@www.acme.com:9000/dir/index.html?query=term#fragment" | urlsplit("query") }}'
    # => 'query=term'

    path: '{{ "http://user:password@www.acme.com:9000/dir/index.html?query=term#fragment" | urlsplit("path") }}'
    # => '/dir/index.html'

Return Values

Key Data Type Description Returned
_value any A dictionary with components as keyword and their value. If O(query) is provided, a string or integer will be returned instead, depending on O(query).