Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate-modules: Fix net_tools modules #52489

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/ansible/modules/net_tools/basics/get_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type

# see examples/playbooks/get_url.yml

ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'core'}
Expand Down Expand Up @@ -162,6 +160,11 @@
- If C(client_cert) contains both the certificate and key, this option is not required.
type: path
version_added: '2.4'
http_agent:
dagwieers marked this conversation as resolved.
Show resolved Hide resolved
description:
- Header to identify as, generally appears in web server logs.
type: str
default: ansible-httpget
# informational: requirements for nodes
extends_documentation_fragment:
- files
Expand Down
1 change: 1 addition & 0 deletions lib/ansible/modules/net_tools/basics/slurp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- The file on the remote system to fetch. This I(must) be a file, not a directory.
type: path
required: true
aliases: [ path ]
notes:
- This module returns an 'in memory' base64 encoded version of the file, take into account that this will require at least twice the RAM as the
original file size.
Expand Down
48 changes: 26 additions & 22 deletions lib/ansible/modules/net_tools/basics/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
- A path of where to download the file to (if desired). If I(dest) is a
directory, the basename of the file on the remote server will be used.
type: path
user:
url_username:
description:
- A username for the module to use for Digest, Basic or WSSE authentication.
type: str
password:
aliases: [ user ]
url_password:
description:
- A password for the module to use for Digest, Basic or WSSE authentication.
type: str
aliases: [ password ]
body:
description:
- The body of the http request/response to the web service. If C(body_format) is set
Expand Down Expand Up @@ -102,7 +104,7 @@
description:
- A list of valid, numeric, HTTP status codes that signifies success of the request.
type: list
default: 200
default: [ 200 ]
timeout:
description:
- The socket level timeout in seconds
Expand Down Expand Up @@ -174,6 +176,11 @@
description:
- Path to Unix domain socket to use for connection
version_added: '2.8'
http_agent:
dagwieers marked this conversation as resolved.
Show resolved Hide resolved
description:
- Header to identify as, generally appears in web server logs.
type: str
default: ansible-httpget
notes:
- The dependency on httplib2 was removed in Ansible 2.1.
- The module returns all the HTTP headers in lower-case.
Expand All @@ -190,9 +197,8 @@
uri:
url: http://www.example.com

# Check that a page returns a status 200 and fail if the word AWESOME is not
# in the page contents.
- uri:
- name: Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents
uri:
url: http://www.example.com
return_content: yes
register: this
Expand All @@ -201,18 +207,16 @@
- name: Create a JIRA issue
uri:
url: https://your.jira.example.com/rest/api/2/issue/
method: POST
user: your_username
password: your_pass
method: POST
body: "{{ lookup('file','issue.json') }}"
force_basic_auth: yes
status_code: 201
body_format: json

# Login to a form based webpage, then use the returned cookie to
# access the app in later tasks

- uri:
- name: Login to a form based webpage, then use the returned cookie to access the app in later tasks
uri:
url: https://your.form.based.auth.example.com/index.php
method: POST
body_format: form-urlencoded
Expand All @@ -223,8 +227,8 @@
status_code: 302
register: login

# Same, but now using a list of tuples
- uri:
- name: Login to a form based webpage using a list of tuples
uri:
url: https://your.form.based.auth.example.com/index.php
method: POST
body_format: form-urlencoded
Expand All @@ -235,7 +239,8 @@
status_code: 302
register: login

- uri:
- name: Connect to website using a previously stored cookie
uri:
url: https://your.form.based.auth.example.com/dashboard.php
method: GET
return_content: yes
Expand All @@ -245,24 +250,24 @@
- name: Queue build of a project in Jenkins
uri:
url: http://{{ jenkins.host }}/job/{{ jenkins.job }}/build?token={{ jenkins.token }}
method: GET
user: "{{ jenkins.user }}"
password: "{{ jenkins.password }}"
method: GET
force_basic_auth: yes
status_code: 201

- name: POST from contents of local file
uri:
url: "https://httpbin.org/post"
url: https://httpbin.org/post
method: POST
src: file.json

- name: POST from contents of remote file
uri:
url: "https://httpbin.org/post"
url: https://httpbin.org/post
method: POST
src: /path/to/my/file.json
remote_src: true
remote_src: yes
'''

RETURN = r'''
Expand Down Expand Up @@ -301,7 +306,6 @@
import shutil
import sys
import tempfile
import traceback

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import PY2, iteritems, string_types
Expand All @@ -327,7 +331,7 @@ def write_file(module, url, dest, content, resp):
except Exception as e:
os.remove(tmpsrc)
msg = format_message("Failed to create temporary content file: %s" % to_native(e), resp)
module.fail_json(msg=msg, exception=traceback.format_exc(), **resp)
module.fail_json(msg=msg, **resp)
f.close()

checksum_src = None
Expand Down Expand Up @@ -368,7 +372,7 @@ def write_file(module, url, dest, content, resp):
except Exception as e:
os.remove(tmpsrc)
msg = format_message("failed to copy %s to %s: %s" % (tmpsrc, dest, to_native(e)), resp)
module.fail_json(msg=msg, exception=traceback.format_exc(), **resp)
module.fail_json(msg=msg, **resp)

os.remove(tmpsrc)

Expand Down Expand Up @@ -449,7 +453,7 @@ def uri(module, url, dest, body, body_format, method, headers, socket_timeout):
})
data = open(src, 'rb')
except OSError:
module.fail_json(msg='Unable to open source file %s' % src, exception=traceback.format_exc(), elapsed=0)
module.fail_json(msg='Unable to open source file %s' % src, elapsed=0)
else:
data = body

Expand Down