mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
consul_kv: PEP8 compliancy and doc fixes (#32340)
This PR includes: - PEP8 compliancy - Doc fixes
This commit is contained in:
parent
daaf8ca86c
commit
a1d60741a7
1 changed files with 67 additions and 75 deletions
|
@ -14,24 +14,25 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
|
|
||||||
DOCUMENTATION = """
|
DOCUMENTATION = """
|
||||||
module: consul_kv
|
module: consul_kv
|
||||||
short_description: Manipulate entries in the key/value store of a consul cluster.
|
short_description: Manipulate entries in the key/value store of a consul cluster
|
||||||
description:
|
description:
|
||||||
- Allows the addition, modification and deletion of key/value entries in a
|
- Allows the addition, modification and deletion of key/value entries in a
|
||||||
consul cluster via the agent. The entire contents of the record, including
|
consul cluster via the agent. The entire contents of the record, including
|
||||||
the indices, flags and session are returned as 'value'.
|
the indices, flags and session are returned as 'value'.
|
||||||
- If the key represents a prefix then Note that when a value is removed, the existing
|
- If the key represents a prefix then Note that when a value is removed, the existing
|
||||||
value if any is returned as part of the results.
|
value if any is returned as part of the results.
|
||||||
- "See http://www.consul.io/docs/agent/http.html#kv for more details."
|
- See http://www.consul.io/docs/agent/http.html#kv for more details.
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.6"
|
- python >= 2.6
|
||||||
- python-consul
|
- python-consul
|
||||||
- requests
|
- requests
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
author: "Steve Gargan (@sgargan)"
|
author:
|
||||||
|
- Steve Gargan (@sgargan)
|
||||||
options:
|
options:
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- the action to take with the supplied key and value. If the state is
|
- The action to take with the supplied key and value. If the state is
|
||||||
'present', the key contents will be set to the value supplied,
|
'present', the key contents will be set to the value supplied,
|
||||||
'changed' will be set to true only if the value was different to the
|
'changed' will be set to true only if the value was different to the
|
||||||
current contents. The state 'absent' will remove the key/value pair,
|
current contents. The state 'absent' will remove the key/value pair,
|
||||||
|
@ -41,97 +42,84 @@ options:
|
||||||
'release' respectively. a valid session must be supplied to make the
|
'release' respectively. a valid session must be supplied to make the
|
||||||
attempt changed will be true if the attempt is successful, false
|
attempt changed will be true if the attempt is successful, false
|
||||||
otherwise.
|
otherwise.
|
||||||
required: false
|
choices: [ absent, acquire, present, release ]
|
||||||
choices: ['present', 'absent', 'acquire', 'release']
|
|
||||||
default: present
|
default: present
|
||||||
key:
|
key:
|
||||||
description:
|
description:
|
||||||
- the key at which the value should be stored.
|
- The key at which the value should be stored.
|
||||||
required: true
|
required: yes
|
||||||
value:
|
value:
|
||||||
description:
|
description:
|
||||||
- the value should be associated with the given key, required if state
|
- The value should be associated with the given key, required if C(state)
|
||||||
is present
|
is C(present).
|
||||||
required: true
|
required: yes
|
||||||
recurse:
|
recurse:
|
||||||
description:
|
description:
|
||||||
- if the key represents a prefix, each entry with the prefix can be
|
- If the key represents a prefix, each entry with the prefix can be
|
||||||
retrieved by setting this to true.
|
retrieved by setting this to C(yes).
|
||||||
required: false
|
type: bool
|
||||||
default: false
|
default: 'no'
|
||||||
session:
|
session:
|
||||||
description:
|
description:
|
||||||
- the session that should be used to acquire or release a lock
|
- The session that should be used to acquire or release a lock
|
||||||
associated with a key/value pair
|
associated with a key/value pair.
|
||||||
required: false
|
|
||||||
default: None
|
|
||||||
token:
|
token:
|
||||||
description:
|
description:
|
||||||
- the token key indentifying an ACL rule set that controls access to
|
- The token key indentifying an ACL rule set that controls access to
|
||||||
the key value pair
|
the key value pair
|
||||||
required: false
|
|
||||||
default: None
|
|
||||||
cas:
|
cas:
|
||||||
description:
|
description:
|
||||||
- used when acquiring a lock with a session. If the cas is 0, then
|
- 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
|
Consul will only put the key if it does not already exist. If the
|
||||||
cas value is non-zero, then the key is only set if the index matches
|
C(cas) value is non-zero, then the key is only set if the index matches
|
||||||
the ModifyIndex of that key.
|
the ModifyIndex of that key.
|
||||||
required: false
|
|
||||||
default: None
|
|
||||||
flags:
|
flags:
|
||||||
description:
|
description:
|
||||||
- opaque integer value that can be passed when setting a value.
|
- Opaque integer value that can be passed when setting a value.
|
||||||
required: false
|
|
||||||
default: None
|
|
||||||
host:
|
host:
|
||||||
description:
|
description:
|
||||||
- host of the consul agent defaults to localhost
|
- Host of the consul agent.
|
||||||
required: false
|
|
||||||
default: localhost
|
default: localhost
|
||||||
port:
|
port:
|
||||||
description:
|
description:
|
||||||
- the port on which the consul agent is running
|
- The port on which the consul agent is running.
|
||||||
required: false
|
|
||||||
default: 8500
|
default: 8500
|
||||||
scheme:
|
scheme:
|
||||||
description:
|
description:
|
||||||
- the protocol scheme on which the consul agent is running
|
- The protocol scheme on which the consul agent is running.
|
||||||
required: false
|
|
||||||
default: http
|
default: http
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
validate_certs:
|
validate_certs:
|
||||||
description:
|
description:
|
||||||
- whether to verify the tls certificate of the consul agent
|
- Whether to verify the tls certificate of the consul agent.
|
||||||
required: false
|
type: bool
|
||||||
default: True
|
default: 'yes'
|
||||||
version_added: "2.1"
|
version_added: "2.1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
- name: Add or update the value associated with a key in the key/value store
|
||||||
|
consul_kv:
|
||||||
|
key: somekey
|
||||||
|
value: somevalue
|
||||||
|
|
||||||
- name: add or update the value associated with a key in the key/value store
|
- name: Remove a key from the store
|
||||||
consul_kv:
|
consul_kv:
|
||||||
key: somekey
|
key: somekey
|
||||||
value: somevalue
|
state: absent
|
||||||
|
|
||||||
- name: remove a key from the store
|
- name: Add a node to an arbitrary group via consul inventory (see consul.ini)
|
||||||
consul_kv:
|
consul_kv:
|
||||||
key: somekey
|
key: ansible/groups/dc1/somenode
|
||||||
state: absent
|
value: top_secret
|
||||||
|
|
||||||
- name: add a node to an arbitrary group via consul inventory (see consul.ini)
|
- name: Register a key/value pair with an associated session
|
||||||
consul_kv:
|
consul_kv:
|
||||||
key: ansible/groups/dc1/somenode
|
key: stg/node/server_birthday
|
||||||
value: 'top_secret'
|
value: 20160509
|
||||||
|
session: "{{ sessionid }}"
|
||||||
- name: Register a key/value pair with an associated session
|
state: acquire
|
||||||
consul_kv:
|
|
||||||
key: stg/node/server_birthday
|
|
||||||
value: 20160509
|
|
||||||
session: "{{ sessionid }}"
|
|
||||||
state: acquire
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -249,31 +237,35 @@ def test_dependencies(module):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
argument_spec = dict(
|
module = AnsibleModule(
|
||||||
cas=dict(required=False),
|
argument_spec=dict(
|
||||||
flags=dict(required=False),
|
cas=dict(type='str'),
|
||||||
key=dict(required=True),
|
flags=dict(type='str'),
|
||||||
host=dict(default='localhost'),
|
key=dict(type='str', required=True),
|
||||||
scheme=dict(required=False, default='http'),
|
host=dict(type='str', default='localhost'),
|
||||||
validate_certs=dict(required=False, type='bool', default=True),
|
scheme=dict(type='str', default='http'),
|
||||||
port=dict(default=8500, type='int'),
|
validate_certs=dict(type='bool', default=True),
|
||||||
recurse=dict(required=False, type='bool'),
|
port=dict(type='int', default=8500),
|
||||||
retrieve=dict(required=False, type='bool', default=True),
|
recurse=dict(type='bool'),
|
||||||
state=dict(default='present', choices=['present', 'absent', 'acquire', 'release']),
|
retrieve=dict(type='bool', default=True),
|
||||||
token=dict(required=False, no_log=True),
|
state=dict(type='str', default='present', choices=['absent', 'acquire', 'present', 'release']),
|
||||||
value=dict(required=False),
|
token=dict(type='str', no_log=True),
|
||||||
session=dict(required=False)
|
value=dict(type='str'),
|
||||||
|
session=dict(type='str'),
|
||||||
|
),
|
||||||
|
supports_check_mode=False,
|
||||||
|
required_if=[
|
||||||
|
['state', 'present', ['value']],
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec, supports_check_mode=False)
|
|
||||||
|
|
||||||
test_dependencies(module)
|
test_dependencies(module)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
execute(module)
|
execute(module)
|
||||||
except ConnectionError as e:
|
except ConnectionError as e:
|
||||||
module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (
|
module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (
|
||||||
module.params.get('host'), module.params.get('port'), str(e)))
|
module.params.get('host'), module.params.get('port'), e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue