Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/clustering/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyo

�
�Udac@`s ddlmZmZmZeZidd6dgd6dd6ZdZd	Zdd
l	m
Z
y&ddlZddlm
Z
eZWnek
r�eZnXdd
lmZdZd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zedkre�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�
module: consul_kv
short_description: Manipulate entries in the key/value store of a consul cluster
description:
  - Allows the retrieval, addition, modification and deletion of key/value entries in a
    consul cluster via the agent. The entire contents of the record, including
    the indices, flags and session are returned as C(value).
  - If the C(key) represents a prefix then note that when a value is removed, the existing
    value if any is returned as part of the results.
  - See http://www.consul.io/docs/agent/http.html#kv for more details.
requirements:
  - python-consul
  - requests
version_added: "2.0"
author:
  - Steve Gargan (@sgargan)
  - Colin Nolan (@colin-nolan)
options:
    state:
        description:
          - The action to take with the supplied key and value. If the state is 'present' and `value` is set, the key
            contents will be set to the value supplied and `changed` will be set to `true` only if the value was
            different to the current contents. If the state is 'present' and `value` is not set, the existing value
            associated to the key will be returned. The state 'absent' will remove the key/value pair,
            again 'changed' will be set to true only if the key actually existed
            prior to the removal. An attempt can be made to obtain or free the
            lock associated with a key/value pair with the states 'acquire' or
            'release' respectively. a valid session must be supplied to make the
            attempt changed will be true if the attempt is successful, false
            otherwise.
        choices: [ absent, acquire, present, release ]
        default: present
    key:
        description:
          - The key at which the value should be stored.
        type: str
        required: yes
    value:
        description:
          - The value should be associated with the given key, required if C(state)
            is C(present).
        type: str
        required: yes
    recurse:
        description:
          - If the key represents a prefix, each entry with the prefix can be
            retrieved by setting this to C(yes).
        type: bool
        default: 'no'
    retrieve:
        description:
            - If the I(state) is C(present) and I(value) is set, perform a
              read after setting the value and return this value.
        default: True
        type: bool
    session:
        description:
          - The session that should be used to acquire or release a lock
            associated with a key/value pair.
        type: str
    token:
        description:
          - The token key identifying an ACL rule set that controls access to
            the key value pair
        type: str
    cas:
        description:
          - Used when acquiring a lock with a session. If the C(cas) is C(0), then
            Consul will only put the key if it does not already exist. If the
            C(cas) value is non-zero, then the key is only set if the index matches
            the ModifyIndex of that key.
        type: str
    flags:
        description:
          - Opaque positive integer value that can be passed when setting a value.
        type: str
    host:
        description:
          - Host of the consul agent.
        type: str
        default: localhost
    port:
        description:
          - The port on which the consul agent is running.
        type: int
        default: 8500
    scheme:
        description:
          - The protocol scheme on which the consul agent is running.
        type: str
        default: http
        version_added: "2.1"
    validate_certs:
        description:
          - Whether to verify the tls certificate of the consul agent.
        type: bool
        default: 'yes'
        version_added: "2.1"
sK
# If the key does not exist, the value associated to the "data" property in `retrieved_key` will be `None`
# If the key value is empty string, `retrieved_key["data"]["Value"]` will be `None`
- name: retrieve a value from the key/value store
  consul_kv:
    key: somekey
  register: retrieved_key

- name: Add or update the value associated with a key in the key/value store
  consul_kv:
    key: somekey
    value: somevalue

- name: Remove a key from the store
  consul_kv:
    key: somekey
    state: absent

- name: Add a node to an arbitrary group via consul inventory (see consul.ini)
  consul_kv:
    key: ansible/groups/dc1/somenode
    value: top_secret

- name: Register a key/value pair with an associated session
  consul_kv:
    key: stg/node/server_birthday
    value: 20160509
    session: "{{ sessionid }}"
    state: acquire
(tto_textN(tConnectionError(t
AnsibleModulecC`sq|jj|�\}}|s(|tfSy*t|ddd�|k}||fSWntk
rl|tfSXdS(s�
    Uses the given Consul client to determine if the value associated to the given key is different to the given target
    value.
    :param consul_client: Consul connected client
    :param key: key in Consul
    :param target_value: value to be associated to the key
    :return: tuple where the first element is the value of the "X-Consul-Index" header and the second is `True` if the
    value has changed (i.e. the stored value is not the target value)
    tValueterrorstsurrogate_or_strictN(tkvtgettTrueRtUnicodeError(t
consul_clienttkeyttarget_valuetindextexistingtchanged((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyt_has_value_changed�s


cC`s�|jjd�}|dks*|dkr:t||�nn|dkrx|jjd�tkrkt|�q�t|�n0|dkr�t|�n|jdd|f�dS(	NtstatetacquiretreleasetpresenttvaluetabsenttmsgsUnsupported state: %s(tparamsRtlocktNOT_SETt	get_valuet	set_valuetremove_valuet	exit_json(tmoduleR((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pytexecute�s


cC`s=t|�}|jjd�}|jjd�}|jjd�}|se|jdd||f�nt|||�\}}|r|jr|dkr�|jj||d|jjd�d|d|jjd��}q|jj||d|jjd�d	|d|jjd��}n|jd
|d|d|�dS(NtsessionRRRs3%s of lock for %s requested but no session suppliedRtcastflagsRRR(	tget_consul_apiR RtfailRt
check_modeRtputR&(R'Rt
consul_apiR)RRRR((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyR!�s,	cC`sht|�}|jjd�}|jj|d|jjd��\}}|jdtd|d|�dS(NRtrecurseRRtdata(R,R RRR&tFalse(R'R0RRtexisting_value((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyR#�s*c
C`st|�}|jjd�}|jjd�}|tkrOtd|��nt|||�\}}|r�|jr�|jj||d|jjd�d|jjd��}nd}|jjd�r�|jj|�\}}n|j
d|d|d|d	|�dS(
NRRs%Cannot set value of "%s" to `NOT_SET`R*R+tretrieveRRR2(R,R RR"tAssertionErrorRR.RR/tNoneR&(R'R0RRRRtstored((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyR$�s"c
C`s�t|�}|jjd�}|jj|d|jjd��\}}|dk	}|r�|jr�|jj||jjd��n|jd|d|d|d|�dS(s� remove the value associated with the given key. if the recurse parameter
     is set then any key prefixed with the given key will be removed. RR1RRR2N(R,R RRR7R.tdeleteR&(R'R0RRRR((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyR%
s	!"cC`sdtjd|jjd�d|jjd�d|jjd�d|jjd�d|jjd��S(Nthosttporttschemetverifytvalidate_certsttoken(tconsultConsulR R(R'R?((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyR,!s
cC`sts|jdd�ndS(NRshpython-consul required for this module. see https://python-consul.readthedocs.io/en/latest/#installation(tpython_consul_installedt	fail_json(R'((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyttest_dependencies)sc C`s�tdtdtdd�dtdd�dtdddt�dtddd	d
�dtddd	d�d
tddd	t�dtddd	d�dtdd�dtddd	t�dtddd	ddddddg�dtdddt�dtddd	t�dtdd��
dt�}t|�yt|�Wnptk
r�}|jdd |jj	d�|jj	d�|f�n)t
k
r�}|jdt|��nXdS(!Nt
argument_specR*ttypetstrR+RtrequiredR:tdefaultt	localhostR<thttpR>tboolR;tinti4!R1R5RRtchoicesRRRR?tno_logRR)tsupports_check_modeRs8Could not connect to consul agent at %s:%s, error was %s(R
tdictRR"RDR(R	RCR Rt	ExceptionRG(R'te((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pytmain/s0'	
,t__main__( t
__future__RRRRFt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStansible.module_utils._textRR@trequests.exceptionsR	RRBtImportErrorR3tansible.module_utils.basicR
R7R"RR(R!R#R$R%R,RDRTt__name__(((sH/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul_kv.pyt<module>s4


e 


			 						 

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]