ansible.builtin.url (v2.11.12) — lookup

return contents from URL

| "added in version" 1.9 of ansible.builtin"

Authors: Brian Coca (@bcoca)

Install Ansible via pip

Install with pip install ansible-core==2.11.12

Description

Returns the content of the URL requested to be used as data in play.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: url lookup splits lines by default
  debug: msg="{{item}}"
  loop: "{{ lookup('url', 'https://github.com/gremlin.keys', wantlist=True) }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: display ip ranges
  debug: msg="{{ lookup('url', 'https://ip-ranges.amazonaws.com/ip-ranges.json', split_lines=False) }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: url lookup using authentication
  debug: msg="{{ lookup('url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: url lookup using basic authentication
  debug: msg="{{ lookup('url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2', force_basic_auth='True') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: url lookup using headers
  debug: msg="{{ lookup('url', 'https://some.private.site.com/api/service', headers={'header1':'value1', 'header2':'value2'} ) }}"

Inputs

    
force:
    default: false
    description: Whether or not to set "cache-control" header with value "no-cache"
    env:
    - name: ANSIBLE_LOOKUP_URL_FORCE
    ini:
    - key: force
      section: url_lookup
    type: boolean
    vars:
    - name: ansible_lookup_url_force
    version_added: '2.10'
    version_added_collection: ansible.builtin

_terms:
    description: urls to query

ca_path:
    description: String of file system path to CA cert bundle to use
    env:
    - name: ANSIBLE_LOOKUP_URL_CA_PATH
    ini:
    - key: ca_path
      section: url_lookup
    type: string
    vars:
    - name: ansible_lookup_url_ca_path
    version_added: '2.10'
    version_added_collection: ansible.builtin

headers:
    default: {}
    description: HTTP request headers
    type: dictionary
    version_added: '2.9'
    version_added_collection: ansible.builtin

timeout:
    default: 10
    description: How long to wait for the server to send data before giving up
    env:
    - name: ANSIBLE_LOOKUP_URL_TIMEOUT
    ini:
    - key: timeout
      section: url_lookup
    type: float
    vars:
    - name: ansible_lookup_url_timeout
    version_added: '2.10'
    version_added_collection: ansible.builtin

password:
    description: Password to use for HTTP authentication.
    type: string
    version_added: '2.8'
    version_added_collection: ansible.builtin

username:
    description: Username to use for HTTP authentication.
    type: string
    version_added: '2.8'
    version_added_collection: ansible.builtin

use_proxy:
    default: true
    description: Flag to control if the lookup will observe HTTP proxy environment variables
      when present.
    type: boolean

http_agent:
    default: ansible-httpget
    description: User-Agent to use in the request. The default was changed in 2.11 to
      C(ansible-httpget).
    env:
    - name: ANSIBLE_LOOKUP_URL_AGENT
    ini:
    - key: agent
      section: url_lookup
    type: string
    vars:
    - name: ansible_lookup_url_agent
    version_added: '2.10'
    version_added_collection: ansible.builtin

use_gssapi:
    default: false
    description:
    - Use GSSAPI handler of requests
    - As of Ansible 2.11, GSSAPI credentials can be specified with I(username) and I(password).
    env:
    - name: ANSIBLE_LOOKUP_URL_USE_GSSAPI
    ini:
    - key: use_gssapi
      section: url_lookup
    type: boolean
    vars:
    - name: ansible_lookup_url_use_gssapi
    version_added: '2.10'
    version_added_collection: ansible.builtin

split_lines:
    default: true
    description: Flag to control if content is returned as a list of lines or as a single
      text blob
    type: boolean

unix_socket:
    description: String of file system path to unix socket file to use when establishing
      connection to the provided url
    env:
    - name: ANSIBLE_LOOKUP_URL_UNIX_SOCKET
    ini:
    - key: unix_socket
      section: url_lookup
    type: string
    vars:
    - name: ansible_lookup_url_unix_socket
    version_added: '2.10'
    version_added_collection: ansible.builtin

validate_certs:
    default: true
    description: Flag to control SSL certificate validation
    type: boolean

follow_redirects:
    default: urllib2
    description: String of urllib2, all/yes, safe, none to determine how redirects are
      followed, see RedirectHandlerFactory for more information
    env:
    - name: ANSIBLE_LOOKUP_URL_FOLLOW_REDIRECTS
    ini:
    - key: follow_redirects
      section: url_lookup
    type: string
    vars:
    - name: ansible_lookup_url_follow_redirects
    version_added: '2.10'
    version_added_collection: ansible.builtin

force_basic_auth:
    default: false
    description: Force basic authentication
    env:
    - name: ANSIBLE_LOOKUP_URL_AGENT
    ini:
    - key: agent
      section: url_lookup
    type: boolean
    vars:
    - name: ansible_lookup_url_agent
    version_added: '2.10'
    version_added_collection: ansible.builtin

unredirected_headers:
    description: A list of headers to not attach on a redirected request
    env:
    - name: ANSIBLE_LOOKUP_URL_UNREDIR_HEADERS
    ini:
    - key: unredirected_headers
      section: url_lookup
    type: list
    vars:
    - name: ansible_lookup_url_unredir_headers
    version_added: '2.10'
    version_added_collection: ansible.builtin

Outputs

_list:
  description: list of list of lines or content of url(s)
  elements: str
  type: list