관리-도구
편집 파일: uri.cpython-39.opt-1.pyc
a �����)g#o����������������������@���s0��d�dl�mZmZmZ�eZdZdZdZd�dl Z d�dl Z d�dlZd�dlZd�dl Z d�dlZd�dlZd�dlmZmZ�d�dlmZmZmZmZmZ�d�dlmZmZ�d�d lmZmZ�d�d lm Z m!Z!�d�dl"m#Z#m$Z$m%Z%m&Z&m'Z'�dd hZ(e)d�Z*dd��Z+dd��Z,dd��Z-dd��Z.dd��Z/dd��Z0dd��Z1e2dk�r,e1���dS�)�����)�absolute_import�division�print_functiona�&�� --- module: uri short_description: Interacts with webservices description: - Interacts with HTTP and HTTPS web services and supports Digest, Basic and WSSE HTTP authentication mechanisms. - For Windows targets, use the M(ansible.windows.win_uri) module instead. version_added: "1.1" options: ciphers: description: - SSL/TLS Ciphers to use for the request. - 'When a list is provided, all ciphers are joined in order with C(:)' - See the L(OpenSSL Cipher List Format,https://www.openssl.org/docs/manmaster/man1/openssl-ciphers.html#CIPHER-LIST-FORMAT) for more details. - The available ciphers is dependent on the Python and OpenSSL/LibreSSL versions type: list elements: str version_added: '2.14' decompress: description: - Whether to attempt to decompress gzip content-encoded responses type: bool default: true version_added: '2.14' url: description: - HTTP or HTTPS URL in the form (http|https)://host.domain[:port]/path type: str required: true dest: description: - 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 url_username: description: - A username for the module to use for Digest, Basic or WSSE authentication. type: str 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 to 'json' it will take an already formatted JSON string or convert a data structure into JSON. - If C(body_format) is set to 'form-urlencoded' it will convert a dictionary or list of tuples into an 'application/x-www-form-urlencoded' string. (Added in v2.7) - If C(body_format) is set to 'form-multipart' it will convert a dictionary into 'multipart/form-multipart' body. (Added in v2.10) type: raw body_format: description: - The serialization format of the body. When set to C(json), C(form-multipart), or C(form-urlencoded), encodes the body argument, if needed, and automatically sets the Content-Type header accordingly. - As of v2.3 it is possible to override the C(Content-Type) header, when set to C(json) or C(form-urlencoded) via the I(headers) option. - The 'Content-Type' header cannot be overridden when using C(form-multipart) - C(form-urlencoded) was added in v2.7. - C(form-multipart) was added in v2.10. type: str choices: [ form-urlencoded, json, raw, form-multipart ] default: raw version_added: "2.0" method: description: - The HTTP method of the request or response. - In more recent versions we do not restrict the method at the module level anymore but it still must be a valid method accepted by the service handling the request. type: str default: GET return_content: description: - Whether or not to return the body of the response as a "content" key in the dictionary result no matter it succeeded or failed. - Independently of this option, if the reported Content-type is "application/json", then the JSON is always loaded into a key called C(json) in the dictionary results. type: bool default: no force_basic_auth: description: - Force the sending of the Basic authentication header upon initial request. - When this setting is C(false), this module will first try an unauthenticated request, and when the server replies with an C(HTTP 401) error, it will submit the Basic authentication header. - When this setting is C(true), this module will immediately send a Basic authentication header on the first request. - "Use this setting in any of the following scenarios:" - You know the webservice endpoint always requires HTTP Basic authentication, and you want to speed up your requests by eliminating the first roundtrip. - The web service does not properly send an HTTP 401 error to your client, so Ansible's HTTP library will not properly respond with HTTP credentials, and logins will fail. - The webservice bans or rate-limits clients that cause any HTTP 401 errors. type: bool default: no follow_redirects: description: - Whether or not the URI module should follow redirects. C(all) will follow all redirects. C(safe) will follow only "safe" redirects, where "safe" means that the client is only doing a GET or HEAD on the URI to which it is being redirected. C(none) will not follow any redirects. Note that C(true) and C(false) choices are accepted for backwards compatibility, where C(true) is the equivalent of C(all) and C(false) is the equivalent of C(safe). C(true) and C(false) are deprecated and will be removed in some future version of Ansible. type: str choices: ['all', 'no', 'none', 'safe', 'urllib2', 'yes'] default: safe creates: description: - A filename, when it already exists, this step will not be run. type: path removes: description: - A filename, when it does not exist, this step will not be run. type: path status_code: description: - A list of valid, numeric, HTTP status codes that signifies success of the request. type: list elements: int default: [ 200 ] timeout: description: - The socket level timeout in seconds type: int default: 30 headers: description: - Add custom HTTP headers to a request in the format of a YAML hash. As of C(2.3) supplying C(Content-Type) here will override the header generated by supplying C(json) or C(form-urlencoded) for I(body_format). type: dict version_added: '2.1' validate_certs: description: - If C(false), SSL certificates will not be validated. - This should only set to C(false) used on personally controlled sites using self-signed certificates. - Prior to 1.9.2 the code defaulted to C(false). type: bool default: true version_added: '1.9.2' client_cert: description: - PEM formatted certificate chain file to be used for SSL client authentication. - This file can also include the key as well, and if the key is included, I(client_key) is not required type: path version_added: '2.4' client_key: description: - PEM formatted file that contains your private key to be used for SSL client authentication. - If I(client_cert) contains both the certificate and key, this option is not required. type: path version_added: '2.4' ca_path: description: - PEM formatted file that contains a CA certificate to be used for validation type: path version_added: '2.11' src: description: - Path to file to be submitted to the remote server. - Cannot be used with I(body). - Should be used with I(force_basic_auth) to ensure success when the remote end sends a 401. type: path version_added: '2.7' remote_src: description: - If C(false), the module will search for the C(src) on the controller node. - If C(true), the module will search for the C(src) on the managed (remote) node. type: bool default: no version_added: '2.7' force: description: - If C(true) do not get a cached copy. type: bool default: no use_proxy: description: - If C(false), it will not use a proxy, even if one is defined in an environment variable on the target hosts. type: bool default: true unix_socket: description: - Path to Unix domain socket to use for connection type: path version_added: '2.8' http_agent: description: - Header to identify as, generally appears in web server logs. type: str default: ansible-httpget unredirected_headers: description: - A list of header names that will not be sent on subsequent redirected requests. This list is case insensitive. By default all headers will be redirected. In some cases it may be beneficial to list headers such as C(Authorization) here to avoid potential credential exposure. default: [] type: list elements: str version_added: '2.12' use_gssapi: description: - Use GSSAPI to perform the authentication, typically this is for Kerberos or Kerberos through Negotiate authentication. - Requires the Python library L(gssapi,https://github.com/pythongssapi/python-gssapi) to be installed. - Credentials for GSSAPI can be specified with I(url_username)/I(url_password) or with the GSSAPI env var C(KRB5CCNAME) that specified a custom Kerberos credential cache. - NTLM authentication is C(not) supported even if the GSSAPI mech for NTLM has been installed. type: bool default: no version_added: '2.11' use_netrc: description: - Determining whether to use credentials from ``~/.netrc`` file - By default .netrc is used with Basic authentication headers - When set to False, .netrc credentials are ignored type: bool default: true version_added: '2.14' extends_documentation_fragment: - action_common_attributes - files attributes: check_mode: support: none diff_mode: support: none platform: platforms: posix notes: - The dependency on httplib2 was removed in Ansible 2.1. - The module returns all the HTTP headers in lower-case. - For Windows targets, use the M(ansible.windows.win_uri) module instead. seealso: - module: ansible.builtin.get_url - module: ansible.windows.win_uri author: - Romeo Theriault (@romeotheriault) ap�� - name: Check that you can connect (GET) to a page and it returns a status 200 ansible.builtin.uri: url: http://www.example.com - name: Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents ansible.builtin.uri: url: http://www.example.com return_content: true register: this failed_when: "'AWESOME' not in this.content" - name: Create a JIRA issue ansible.builtin.uri: url: https://your.jira.example.com/rest/api/2/issue/ user: your_username password: your_pass method: POST body: "{{ lookup('ansible.builtin.file','issue.json') }}" force_basic_auth: true status_code: 201 body_format: json - name: Login to a form based webpage, then use the returned cookie to access the app in later tasks ansible.builtin.uri: url: https://your.form.based.auth.example.com/index.php method: POST body_format: form-urlencoded body: name: your_username password: your_password enter: Sign in status_code: 302 register: login - name: Login to a form based webpage using a list of tuples ansible.builtin.uri: url: https://your.form.based.auth.example.com/index.php method: POST body_format: form-urlencoded body: - [ name, your_username ] - [ password, your_password ] - [ enter, Sign in ] status_code: 302 register: login - name: Upload a file via multipart/form-multipart ansible.builtin.uri: url: https://httpbin.org/post method: POST body_format: form-multipart body: file1: filename: /bin/true mime_type: application/octet-stream file2: content: text based file content filename: fake.txt mime_type: text/plain text_form_field: value - name: Connect to website using a previously stored cookie ansible.builtin.uri: url: https://your.form.based.auth.example.com/dashboard.php method: GET return_content: true headers: Cookie: "{{ login.cookies_string }}" - name: Queue build of a project in Jenkins ansible.builtin.uri: url: http://{{ jenkins.host }}/job/{{ jenkins.job }}/build?token={{ jenkins.token }} user: "{{ jenkins.user }}" password: "{{ jenkins.password }}" method: GET force_basic_auth: true status_code: 201 - name: POST from contents of local file ansible.builtin.uri: url: https://httpbin.org/post method: POST src: file.json - name: POST from contents of remote file ansible.builtin.uri: url: https://httpbin.org/post method: POST src: /path/to/my/file.json remote_src: true - name: Create workspaces in Log analytics Azure ansible.builtin.uri: url: https://www.mms.microsoft.com/Embedded/Api/ConfigDataSources/LogManagementData/Save method: POST body_format: json status_code: [200, 202] return_content: true headers: Content-Type: application/json x-ms-client-workspace-path: /subscriptions/{{ sub_id }}/resourcegroups/{{ res_group }}/providers/microsoft.operationalinsights/workspaces/{{ w_spaces }} x-ms-client-platform: ibiza x-ms-client-auth-token: "{{ token_az }}" body: - name: Pause play until a URL is reachable from this host ansible.builtin.uri: url: "http://192.0.2.1/some/test" follow_redirects: none method: GET register: _result until: _result.status == 200 retries: 720 # 720 * 5 seconds = 1hour (60*60/5) delay: 5 # Every 5 seconds - name: Provide SSL/TLS ciphers as a list uri: url: https://example.org ciphers: - '@SECLEVEL=2' - ECDH+AESGCM - ECDH+CHACHA20 - ECDH+AES - DHE+AES - '!aNULL' - '!eNULL' - '!aDSS' - '!SHA1' - '!AESCCM' - name: Provide SSL/TLS ciphers as an OpenSSL formatted cipher list uri: url: https://example.org ciphers: '@SECLEVEL=2:ECDH+AESGCM:ECDH+CHACHA20:ECDH+AES:DHE+AES:!aNULL:!eNULL:!aDSS:!SHA1:!AESCCM' a��� # The return information includes all the HTTP headers in lower-case. content: description: The response body content. returned: status not in status_code or return_content is true type: str sample: "{}" cookies: description: The cookie values placed in cookie jar. returned: on success type: dict sample: {"SESSIONID": "[SESSIONID]"} version_added: "2.4" cookies_string: description: The value for future request Cookie headers. returned: on success type: str sample: "SESSIONID=[SESSIONID]" version_added: "2.6" elapsed: description: The number of seconds that elapsed while performing the download. returned: on success type: int sample: 23 msg: description: The HTTP message from the request. returned: always type: str sample: OK (unknown bytes) path: description: destination file/path returned: dest is defined type: str sample: /path/to/file.txt redirected: description: Whether the request was redirected. returned: on success type: bool sample: false status: description: The HTTP status code from the request. returned: always type: int sample: 200 url: description: The actual URL used for the request. returned: always type: str sample: https://www.ansible.com/ N)� AnsibleModule� sanitize_keys)�PY2�PY3�binary_type� iteritems�string_types)� urlencode�urlsplit)� to_native�to_text)�Mapping�Sequence)� fetch_url�get_response_filename�parse_content_type�prepare_multipart�url_argument_spec�jsonZ javascript)�msg� exception�warningsZdeprecationsZfailedZskipped�changed�rc�stdout�stderr�elapsed�path�location�content_typec�����������������C���s���|��d�}|�|rd|�nd�S�)Nr���z %s��)�pop)�err�respr�����r'����7/usr/lib/python3.9/site-packages/ansible/modules/uri.py�format_message���s���� r)���c�������������� ���C���s���d}zdt�j|�jd�\}}t�|d��2}t|t�r<|�|��nt� ||��W�d����n1�s\0����Y��W�nd�t y��}�zL|r�tj�|�r�t� |��tdt|��|�}|�jf�d|i|���W�Y�d}~n d}~0�0�|��|�} |��|�} | | k�rhz|��||��W�nj�t �yf�}�zPtj�|��r&t� |��td||t|�f�|�}|�jf�d|i|���W�Y�d}~n d}~0�0�tj�|��r�t� |��dS�)zQ Create temp file and write content to dest file only if content changed N)�dir�wbz+Failed to create temporary content file: %sr���zfailed to copy %s to %s: %s)�tempfileZmkstempZtmpdir�os�fdopen� isinstancer ����write�shutil�copyfileobj� Exceptionr ����exists�remover)���r���� fail_jsonZsha1Zatomic_move)�module�dest�contentr&���Ztmpsrc�fd�f�er���Zchecksum_srcZ checksum_destr'���r'���r(���� write_file���s0���� . * *r=���c�����������������C���sd���d|v�r|S�|��d�r:t|��}|��|d�d�}d||f�S�|��d�s\tj�|��}d||f�S�|S�dS�)z�Attempts to create an absolute URL based on initial URL, and next URL, specifically in the case of a ``Location`` header. z://�/����r#���z%s%sz%s/%sN)� startswithr ����replacer-���r ����dirname)�urlr!����parts�baser'���r'���r(����absolute_location���s���� rF���c�����������������C���s@���|�du�rdS�t�|�t�rt|��S�t�|�t�r4t|�����S�td��dS�)z. Convert data into a list of key-value tuples Nz/cannot form-urlencode body, expect list or dict)r/���r����listr����items� TypeError)�datar'���r'���r(����kv_list��s���� rK���c�����������������C���s����t�|�t�r|�S�t�|�ttf�r�g�}t|��D�]N\}}t�|t�sHt�|ttf�sN|g}|D�]"}|durR|�t|�t|�f��qRq(t|dd�S�|�S�)z, Convert data into a form-urlencoded string NT)�doseq)r/���r���r���r���rK����appendr���r���)�body�result�key�values�valuer'���r'���r(����form_urlencoded��s���� rS���c �����������������C���s����|�j�d�} | rZz$|�dt�| �ji��t| d�}W�q^�tyV���|�jd| �dd��Y�q^0�n|}i�}|d�ur�tj� |�r�t j �tj�|��|d<�t |�|f|||||�j�d�|| |�j�d �| ||d �|��\}}| r�z|����W�n�ty����Y�n0�||fS�)N�srczContent-Length�rbzUnable to open source file %sr����r���r���Z last_mod_time�unix_socket� use_proxy)rJ����headers�method�timeoutrW����ca_path�unredirected_headersrX���� decompress�ciphers� use_netrc)�params�updater-����stat�st_size�open�OSErrorr6���r ����isfile�datetimeZutcfromtimestamp�getmtimer����closer3���)r7���rC���r8���rN����body_formatrZ���rY����socket_timeoutr\���r]���r^���r_���r`���rT���rJ����kwargsr&����infor'���r'���r(����uri2��s6���� � �� ro���c������������(������C���s���t���}�|�jtdd�tddgd�tddgdd�td d�tdd g�d �d�tdd�tddd �tddd �tddg�d�d�tdd�tdd�tdddgd�tddd �tdi�d �tdd�tddd �tdd�d �tddg�d�tddd �tddd�tddd �d��t|�dddggd�}|jd�}|jd�}|jd����}|jd����}|jd �}|jd!�}|jd"�}|jd#�} d$d%��t|jd&��D��} |jd'�}|jd(�}|jd)�} |jd*�}|jd+�}|jd,�}|jd-�}t� d.|��s�|j d/d0��|d1k�rt|t��s�t �|�}d2d3d%��| D��v�r�d4| d5<�n�|d6k�r�t|t��spzt|�}W�n<�t�yn�}�z"|j d7t|��d8d9��W�Y�d�}~n d�}~0�0�d2d:d%��| D��v�r�d;| d5<�nb|d<k�r�zt|�\}}W�n>�ttf�y��}�z |j d=t|��d0��W�Y�d�}~n d�}~0�0�|| d5<�|d�u�rtj�|��r|jd>|�dd?��| d�u�rDtj�| ��sD|jd@| �dd?��tj���}t||||||| ||||||� \}}tj���|�j}|�r�|d�u�r�tj�|��r�t|��p�dA}tj�||�}|�r�|jd�u�r�t |�\}}}}ndB}dC}dD}dE}|�r"dF|v��r"|�!dF�dG�}|�o|���t"v�}n|�r<|�o8|���t"v�}nd}|�pV|�pV|dH�| v}|�r�z*t#�r~|jd�u��sz|j$�r~t�|�%��}W�n$�t&tf�y����|�'ddI�}Y�n0�n|�r�|}nd�}i�} |d�|k| dJ<�| �|��|| dK<�t(| dH��| dH<�d| dL<�|�rv|d�u�rv| dH�| v��rn| dH�dMk�rnt)|||| ��d| dL<�||jd<�|j*|j|dN�}!|�+|!| dL��| dL<�|| d<�i�}"t,| �D�]"\}#}$|#�-dOdP����}%|$|"|%<��q�dQ|"v��r�t.||"dQ��|"dQ<�t|t/��rt0||dR�}&|�r zt �1|&�}'|'|"d1<�W�n"�t2�y���t3�rt4�5���Y�n0�nd�}&|j6�r6t7|"|j6t8�}"| dH�| v�r�dS| dH�| |"�9dTdU�f�|"dT<�|�r~|j f�dV|&i|"���n|j f�i�|"���n,|�r�|jf�dV|&i|"���n|jf�i�|"���d�S�)WNr ���)�type�str�user)rp����aliases�passwordT)rp���rs���Zno_log�raw)�form-urlencodedr���ru����form-multipart)rp����default�choicesZGET)rp���rx����boolF�safe)�all�noZnoner{���Zurllib2ZyesrG����int�����)rp����elementsrx��������dict)rp���r����)r8���Zurl_usernameZurl_passwordrN���rk���rT���rZ����return_contentZfollow_redirects�creates�removes�status_coder[���rY���rW���Z remote_srcr\���r]���r^���r_���r`���rN���rT���)� argument_specZadd_file_common_argsZmutually_exclusiverC���rk���rZ���r8���r����r����r����c�����������������S���s���g�|�]}t�|��qS�r'���)r~���)�.0�xr'���r'���r(���� <listcomp>��������zmain.<locals>.<listcomp>r����r[���r\���rY���r]���r^���r_���r`���z^[A-Z]+$zLParameter 'method' needs to be a single word in uppercase, like GET or POST.)r���r���zcontent-typec�����������������S���s���g�|�]}|�����qS�r'�����lower�r�����headerr'���r'���r(���r�������r����zapplication/jsonzContent-Typerv���z+failed to parse body as form_urlencoded: %sr���rV���c�����������������S���s���g�|�]}|�����qS�r'���r����r����r'���r'���r(���r�������r����z!application/x-www-form-urlencodedrw���z*failed to parse body as form-multipart: %szskipped, since '%s' exists)r���r���z"skipped, since '%s' does not existz index.htmlzapplication/octet-streamZapplicationzoctet-streamzutf-8�+r?����statusr����Z redirectedr���r���i0��)r ����-�_r!���)�encodingz!Status code was %s and not %s: %sr���r#���r9���):r���rb���r����r���ra���r�����upperrG����re�matchr6���r/���r���r����dumpsrS���� ValueErrorr���r���rI���r-���r ���r4���Z exit_jsonrh���Zutcnowro���Zseconds�isdirr����join�fpr���� partition�JSON_CANDIDATESr����closed�read�AttributeErrorr$���r~���r=���Zload_file_common_argumentsZset_fs_attributes_if_differentr ���rA���rF���r ���r����loadsr3���r����sysZ exc_clearZ no_log_valuesr����NO_MODIFY_KEYS�get)(r����r7���rC���rN���rk���rZ���r8���r����r����r����r����rl���r\���Zdict_headersr]���r^���r_���r`���r<���r"����start�rrn���r����filenameZ main_typeZsub_typeZcontent_encodingZsub_type_suffixZ maybe_jsonZmaybe_outputr9���r&���Z file_argsZuresprP���rR���ZukeyZ u_contentZjsr'���r'���r(����mainX��s ��� �� , * � r�����__main__)3Z __future__r���r���r���rp���Z __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNrh���r���r-���r����r1���r����r,���Zansible.module_utils.basicr���r���Zansible.module_utils.sixr���r���r ���r ���r���Z+ansible.module_utils.six.moves.urllib.parser���r ���Zansible.module_utils._textr���r���Z/ansible.module_utils.common._collections_compatr���r���Zansible.module_utils.urlsr���r���r���r���r���r����� frozensetr����r)���r=���rF���rK���rS���ro���r�����__name__r'���r'���r'���r(����<module>���sB����u� 3�$&�B