Headers in URL lookup plugin (#59555)

* Update url.py

Allow passing of headers to URL lookup plugin
This commit is contained in:
glyngholm 2019-07-31 12:23:55 -06:00 committed by Brian Coca
parent 730fa78ca4
commit f46eb8ebcd
2 changed files with 12 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- lookup_url - added ability to specify request headers

View file

@ -36,6 +36,11 @@ options:
type: string
default: None
version_added: "2.8"
headers:
description: HTTP request headers
type: dictionary
default: {}
version_added: "2.9"
"""
EXAMPLES = """
@ -48,6 +53,9 @@ EXAMPLES = """
- name: url lookup using authentication
debug: msg="{{ lookup('url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2') }}"
- name: url lookup using headers
debug: msg="{{ lookup('url', 'https://some.private.site.com/api/service', headers={'header1':'value1', 'header2':'value2'} ) }}"
"""
RETURN = """
@ -78,7 +86,8 @@ class LookupModule(LookupBase):
response = open_url(term, validate_certs=self.get_option('validate_certs'),
use_proxy=self.get_option('use_proxy'),
url_username=self.get_option('username'),
url_password=self.get_option('password'))
url_password=self.get_option('password'),
headers=self.get_option('headers'))
except HTTPError as e:
raise AnsibleError("Received HTTP error for %s : %s" % (term, to_native(e)))
except URLError as e: