Headers in URL lookup plugin (#59555)
* Update url.py Allow passing of headers to URL lookup plugin
This commit is contained in:
parent
730fa78ca4
commit
f46eb8ebcd
2 changed files with 12 additions and 1 deletions
2
changelogs/fragments/59555-lookup-url-headers.yaml
Normal file
2
changelogs/fragments/59555-lookup-url-headers.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- lookup_url - added ability to specify request headers
|
|
@ -36,6 +36,11 @@ options:
|
||||||
type: string
|
type: string
|
||||||
default: None
|
default: None
|
||||||
version_added: "2.8"
|
version_added: "2.8"
|
||||||
|
headers:
|
||||||
|
description: HTTP request headers
|
||||||
|
type: dictionary
|
||||||
|
default: {}
|
||||||
|
version_added: "2.9"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = """
|
EXAMPLES = """
|
||||||
|
@ -48,6 +53,9 @@ EXAMPLES = """
|
||||||
|
|
||||||
- name: url lookup using authentication
|
- name: url lookup using authentication
|
||||||
debug: msg="{{ lookup('url', 'https://some.private.site.com/file.txt', username='bob', password='hunter2') }}"
|
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 = """
|
RETURN = """
|
||||||
|
@ -78,7 +86,8 @@ class LookupModule(LookupBase):
|
||||||
response = open_url(term, validate_certs=self.get_option('validate_certs'),
|
response = open_url(term, validate_certs=self.get_option('validate_certs'),
|
||||||
use_proxy=self.get_option('use_proxy'),
|
use_proxy=self.get_option('use_proxy'),
|
||||||
url_username=self.get_option('username'),
|
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:
|
except HTTPError as e:
|
||||||
raise AnsibleError("Received HTTP error for %s : %s" % (term, to_native(e)))
|
raise AnsibleError("Received HTTP error for %s : %s" % (term, to_native(e)))
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
|
|
Loading…
Reference in a new issue