|
|
@ -127,6 +127,7 @@ except ImportError:
|
|
|
|
# python3
|
|
|
|
# python3
|
|
|
|
from urllib.parse import urlencode
|
|
|
|
from urllib.parse import urlencode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_csrf_protection_enabled(module):
|
|
|
|
def is_csrf_protection_enabled(module):
|
|
|
|
resp, info = fetch_url(module,
|
|
|
|
resp, info = fetch_url(module,
|
|
|
|
module.params['url'] + '/api/json',
|
|
|
|
module.params['url'] + '/api/json',
|
|
|
@ -137,6 +138,7 @@ def is_csrf_protection_enabled(module):
|
|
|
|
content = resp.read()
|
|
|
|
content = resp.read()
|
|
|
|
return json.loads(content).get('useCrumbs', False)
|
|
|
|
return json.loads(content).get('useCrumbs', False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_crumb(module):
|
|
|
|
def get_crumb(module):
|
|
|
|
resp, info = fetch_url(module,
|
|
|
|
resp, info = fetch_url(module,
|
|
|
|
module.params['url'] + '/crumbIssuer/api/json',
|
|
|
|
module.params['url'] + '/crumbIssuer/api/json',
|
|
|
@ -147,20 +149,20 @@ def get_crumb(module):
|
|
|
|
content = resp.read()
|
|
|
|
content = resp.read()
|
|
|
|
return json.loads(content)
|
|
|
|
return json.loads(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec=dict(
|
|
|
|
script = dict(required=True, type="str"),
|
|
|
|
script=dict(required=True, type="str"),
|
|
|
|
url = dict(required=False, type="str", default="http://localhost:8080"),
|
|
|
|
url=dict(required=False, type="str", default="http://localhost:8080"),
|
|
|
|
validate_certs = dict(required=False, type="bool", default=True),
|
|
|
|
validate_certs=dict(required=False, type="bool", default=True),
|
|
|
|
user = dict(required=False, no_log=True, type="str",default=None),
|
|
|
|
user=dict(required=False, no_log=True, type="str", default=None),
|
|
|
|
password = dict(required=False, no_log=True, type="str",default=None),
|
|
|
|
password=dict(required=False, no_log=True, type="str", default=None),
|
|
|
|
args = dict(required=False, type="dict", default=None)
|
|
|
|
args=dict(required=False, type="dict", default=None)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['user'] is not None:
|
|
|
|
if module.params['user'] is not None:
|
|
|
|
if module.params['password'] is None:
|
|
|
|
if module.params['password'] is None:
|
|
|
|
module.fail_json(msg="password required when user provided")
|
|
|
|
module.fail_json(msg="password required when user provided")
|
|
|
@ -168,7 +170,6 @@ def main():
|
|
|
|
module.params['url_password'] = module.params['password']
|
|
|
|
module.params['url_password'] = module.params['password']
|
|
|
|
module.params['force_basic_auth'] = True
|
|
|
|
module.params['force_basic_auth'] = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if module.params['args'] is not None:
|
|
|
|
if module.params['args'] is not None:
|
|
|
|
from string import Template
|
|
|
|
from string import Template
|
|
|
|
script_contents = Template(module.params['script']).substitute(module.params['args'])
|
|
|
|
script_contents = Template(module.params['script']).substitute(module.params['args'])
|
|
|
@ -183,7 +184,7 @@ def main():
|
|
|
|
resp, info = fetch_url(module,
|
|
|
|
resp, info = fetch_url(module,
|
|
|
|
module.params['url'] + "/scriptText",
|
|
|
|
module.params['url'] + "/scriptText",
|
|
|
|
data=urlencode({'script': script_contents}),
|
|
|
|
data=urlencode({'script': script_contents}),
|
|
|
|
headers = headers,
|
|
|
|
headers=headers,
|
|
|
|
method="POST")
|
|
|
|
method="POST")
|
|
|
|
|
|
|
|
|
|
|
|
if info["status"] != 200:
|
|
|
|
if info["status"] != 200:
|
|
|
@ -195,10 +196,9 @@ def main():
|
|
|
|
module.fail_json(msg="script failed with stacktrace:\n " + result)
|
|
|
|
module.fail_json(msg="script failed with stacktrace:\n " + result)
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(
|
|
|
|
module.exit_json(
|
|
|
|
output = result,
|
|
|
|
output=result,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|