
    Vhb                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZ d dlmZmZmZmZmZmZ  G d	 d
e      Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
---
module: postgresql_ping
short_description: Check remote PostgreSQL server availability
description:
- Simple module to check remote PostgreSQL server availability.
options:
  login_db:
    description:
    - Name of a database to connect to.
    - The V(db) alias is deprecated and will be removed in version 5.0.0.
    type: str
    aliases:
    - db
  session_role:
    description:
    - Switch to session_role after connecting. The specified session_role must
      be a role that the current login_user is a member of.
    - Permissions checking for SQL commands is carried out as though
      the session_role were the one that had logged in originally.
    type: str
    version_added: '0.2.0'
  trust_input:
    description:
    - If C(false), check whether a value of I(session_role) is potentially dangerous.
    - It makes sense to use C(false) only when SQL injections via I(session_role) are possible.
    type: bool
    default: true
    version_added: '0.2.0'
seealso:
- module: community.postgresql.postgresql_info
attributes:
  check_mode:
    support: full
author:
- Andrew Klychkov (@Andersson007)
extends_documentation_fragment:
- community.postgresql.postgres
a  
# PostgreSQL ping dbsrv server from the shell:
# ansible dbsrv -m postgresql_ping

# In the example below you need to generate certificates previously.
# See https://www.postgresql.org/docs/current/libpq-ssl.html for more information.
- name: >
    Ping PostgreSQL server using non-default credentials and SSL
    registering the return values into the result variable for future use
  community.postgresql.postgresql_ping:
    login_db: protected_db
    login_host: dbsrv
    login_user: secret
    login_password: secret_pass
    ca_cert: /root/root.crt
    ssl_mode: verify-full
  register: result
  # If you need to fail when the server is not available,
  # uncomment the following line:
  # failed_when: not result.is_available

# You can use the registered result with another task
- name: This task should be executed only if the server is available
  # ...
  when: result.is_available == true
a  
is_available:
  description: PostgreSQL server availability.
  returned: success
  type: bool
  sample: true
server_version:
  description: PostgreSQL server version.
  returned: success
  type: dict
  sample: { major: 13, minor: 2, full: '13.2', raw: 'PostgreSQL 13.2 on x86_64-pc-linux-gnu' }
conn_err_msg:
  description: Connection error message.
  returned: success
  type: str
  sample: ''
  version_added: 1.7.0
N)AnsibleModule)check_input)connect_to_dbensure_required_libsexec_sqlget_conn_paramspg_cursor_argspostgres_common_argument_specc                       e Zd Zd Zd Zd Zy)PgPingc                 <    || _         || _        d| _        i | _        y )NF)modulecursoris_availableversion)selfr   r   s      x/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/postgresql/plugins/modules/postgresql_ping.py__init__zPgPing.__init__u   s    !    c                 R    | j                          | j                  | j                  fS )N)get_pg_versionr   r   )r   s    r   doz	PgPing.do{   s#    !!4<<00r   c                    d}t        | |d      d   d   }|sy d| _        |j                         d   }t        j                  d|      }t        |j                  d            }t        |j                  d	            }d }|j                  d
      t        |j                  d
            }t        ||||      | _        ||| j                  d<   y y )NzSELECT version()F)add_to_executedr   r   T   z(\d+)\.(\d+)(?:\.(\d+))?      )majorminorfullrawpatch)	r
   r   splitrematchintgroupdictr   )r   queryr$   r#   mr!   r"   r%   s           r   r   zPgPing.get_pg_version   s    "tUE:1=iH yy{1~HH0$7AGGAJAGGAJ771:!
OE	
 $)DLL! r   N)__name__
__module____qualname__r   r   r    r   r   r   r   t   s    1*r   r   c            
         t               } | j                  t        ddgddddg      t        d      t        dd	
             t        | d	      }|j                  d   st        ||j                  d          d}d}t        ddt               d      }t        |       t        ||j                  d      }t        ||d      \  }}|r||d<   | |j                  di t        }t        ||      }|r9|j                         \  |d<   |d<   |j                          |j                           |j                  di | y )Nstrdbz5.0.0zcommunity.postgresql)namer   collection_name)typealiasesdeprecated_aliases)r7   boolT)r7   default)login_dbsession_roletrust_input)argument_specsupports_check_moder>   r=   F )changedr   server_versionconn_err_msg)warn_db_default)fail_on_connrD   r   rC   r1   )r   updater+   r   paramsr   r	   r   r   r   r   r   r   close	exit_json)r?   r   r   db_connectionresultconn_paramserrpg_pings           r   mainrP      sU   13M54&"#9F 
 u%fd3  
 # F
 =='FFMM.9: FMv	F  !&&--OK&v{OM3
!$~ %%%77 VV$G;B::<8~'7 8Fvr   __main__)
__future__r   r   r   r7   __metaclass__DOCUMENTATIONEXAMPLESRETURNr'   ansible.module_utils.basicr   Fansible_collections.community.postgresql.plugins.module_utils.databaser   Fansible_collections.community.postgresql.plugins.module_utils.postgresr   r	   r
   r   r   r   objectr   rP   r.   r1   r   r   <module>r[      sg    A @&P6
& 
 4 %*V %*Z2j zF r   