From e1ff0feb58537167c205bcbac53afd91209d1457 Mon Sep 17 00:00:00 2001 From: Steve Gargan Date: Sun, 26 Apr 2015 22:27:53 +0100 Subject: [PATCH] documentation tweaks to fix missing arguments and specification of defaults --- lib/ansible/modules/extras/clustering/consul | 99 ++++++++++++------- .../modules/extras/clustering/consul_acl | 13 ++- .../modules/extras/clustering/consul_kv | 30 ++++-- .../modules/extras/clustering/consul_session | 38 +++++++ 4 files changed, 138 insertions(+), 42 deletions(-) diff --git a/lib/ansible/modules/extras/clustering/consul b/lib/ansible/modules/extras/clustering/consul index 15a68f068a2..fec55726539 100644 --- a/lib/ansible/modules/extras/clustering/consul +++ b/lib/ansible/modules/extras/clustering/consul @@ -24,19 +24,19 @@ short_description: "Add, modify & delete services within a consul cluster. description: - registers services and checks for an agent with a consul cluster. A service is some process running on the agent node that should be advertised by - consul's discovery mechanism. It may optionally supply a check definition - that will be used to notify the consul cluster of the health of the service. + consul's discovery mechanism. It may optionally supply a check definition, + a periodic service test to notify the consul cluster of service's health. Checks may also be registered per node e.g. disk usage, or cpu usage and notify the health of the entire node to the cluster. Service level checks do not require a check name or id as these are derived by Consul from the Service name and id respectively by appending 'service:'. - Node level checks require a check_name and optionally a check_id Currently, - there is no complete way to retrieve the script, interval or ttl metadata for - a registered check. Without this metadata it is not possible to tell if - the data supplied with ansible represents a change to a check. As a result - this does not attempt to determine changes and will always report a changed - occurred. An api method is planned to supply this metadata so at that stage - change management will be added. + Node level checks require a check_name and optionally a check_id. + Currently, there is no complete way to retrieve the script, interval or ttl + metadata for a registered check. Without this metadata it is not possible to + tell if the data supplied with ansible represents a change to a check. As a + result this does not attempt to determine changes and will always report a + changed occurred. An api method is planned to supply this metadata so at that + stage change management will be added. version_added: "1.9" author: Steve Gargan (steve.gargan@gmail.com) options: @@ -45,71 +45,105 @@ options: - register or deregister the consul service, defaults to present required: true choices: ['present', 'absent'] + service_name: + desciption: + - Unique name for the service on a node, must be unique per node, + required if registering a service. May be ommitted if registering + a node level check + required: false service_id: description: - the ID for the service, must be unique per node, defaults to the - service name + service name if the service name is supplied required: false + default: service_name if supplied host: description: - - host of the consul agent with which to register the service, - defaults to localhost + - host of the consul agent defaults to localhost + required: false + default: localhost + port: + description: + - the port on which the consul agent is running required: false + default: 8500 notes: description: - Notes to attach to check when registering it. - service_name: - desciption: - - Unique name for the service on a node, must be unique per node, - required if registering a service. May be ommitted if registering - a node level check required: false + default: None service_port: description: - the port on which the service is listening required for - registration of a service. - required: true + registration of a service, i.e. if service_name or service_id is set + required: false tags: description: - a list of tags that will be attached to the service registration. required: false + default: None script: description: - the script/command that will be run periodically to check the health - of the service + of the service. Scripts require an interval and vise versa required: false + default: None interval: description: - - the interval at which the service check will be run. This is by - convention a number with a s or m to signify the units of seconds - or minutes. if none is supplied, m will be appended + - the interval at which the service check will be run. This is a number + with a s or m suffix to signify the units of seconds or minutes e.g + 15s or 1m. If no suffix is supplied, m will be used by default e.g. + 1 will be 1m. Required if the script param is specified. + required: false + default: None check_id: description: - an ID for the service check, defaults to the check name, ignored if - part of service definition. + part of a service definition. + required: false + default: None check_name: description: - a name for the service check, defaults to the check id. required if standalone, ignored if part of service definition. + required: false + default: None + ttl: + description: + - checks can be registered with a ttl instead of a script and interval + this means that the service will check in with the agent before the + ttl expires. If it doesn't the check will be considered failed. + Required if registering a check and the script an interval are missing + Similar to the interval this is a number with a s or m suffix to + signify the units of seconds or minutes e.g 15s or 1m. If no suffix + is supplied, m will be used by default e.g. 1 will be 1m + required: false + default: None + token: + description: + - the token key indentifying an ACL rule set. May be required to + register services. + required: false + default: None """ EXAMPLES = ''' - name: register nginx service with the local consul agent consul: name: nginx - port: 80 + service_port: 80 - name: register nginx service with curl check consul: name: nginx - port: 80 + service_port: 80 script: "curl http://localhost" interval: 60s - name: register nginx with some service tags consul: name: nginx - port: 80 + service_port: 80 tags: - prod - webservers @@ -432,23 +466,22 @@ class ConsulCheck(): def main(): module = AnsibleModule( argument_spec=dict( + host=dict(default='localhost'), + port=dict(default=8500, type='int'), check_id=dict(required=False), check_name=dict(required=False), - host=dict(default='localhost'), - interval=dict(required=False, type='str'), - ttl=dict(required=False, type='str'), check_node=dict(required=False), check_host=dict(required=False), notes=dict(required=False), - port=dict(default=8500, type='int'), script=dict(required=False), service_id=dict(required=False), service_name=dict(required=False), service_port=dict(required=False, type='int'), state=dict(default='present', choices=['present', 'absent']), + interval=dict(required=False, type='str'), + ttl=dict(required=False, type='str'), tags=dict(required=False, type='list'), - token=dict(required=False), - url=dict(default='http://localhost:8500') + token=dict(required=False) ), supports_check_mode=False, ) diff --git a/lib/ansible/modules/extras/clustering/consul_acl b/lib/ansible/modules/extras/clustering/consul_acl index cd5466c53b1..5e50c54431e 100644 --- a/lib/ansible/modules/extras/clustering/consul_acl +++ b/lib/ansible/modules/extras/clustering/consul_acl @@ -22,7 +22,8 @@ module: consul_acl short_description: "manipulate consul acl keys and rules" description: - allows the addition, modification and deletion of ACL keys and associated - rules in a consul cluster via the agent. + rules in a consul cluster via the agent. For more details on using and + configuring ACLs, see https://www.consul.io/docs/internals/acl.html version_added: "1.9" author: Steve Gargan (steve.gargan@gmail.com) options: @@ -53,6 +54,16 @@ options: description: - an list of the rules that should be associated with a given key/token. required: false + host: + description: + - host of the consul agent defaults to localhost + required: false + default: localhost + port: + description: + - the port on which the consul agent is running + required: false + default: 8500 """ EXAMPLES = ''' diff --git a/lib/ansible/modules/extras/clustering/consul_kv b/lib/ansible/modules/extras/clustering/consul_kv index 8999a43319f..a9132a3d1c2 100644 --- a/lib/ansible/modules/extras/clustering/consul_kv +++ b/lib/ansible/modules/extras/clustering/consul_kv @@ -42,8 +42,9 @@ options: 'release' respectively. a valid session must be supplied to make the attempt changed will be true if the attempt is successful, false otherwise. - required: true + required: false choices: ['present', 'absent', 'acquire', 'release'] + default: present key: description: - the key at which the value should be stored. @@ -57,30 +58,43 @@ options: description: - if the key represents a prefix, each entry with the prefix can be retrieved by setting this to true. - required: true + required: false + default: false session: description: - the session that should be used to acquire or release a lock associated with a key/value pair + required: false + default: None token: description: - the token key indentifying an ACL rule set that controls access to the key value pair required: false - url: - description: - - location of the consul agent with which access the keay/value store, - defaults to http://localhost:8500 - required: false + default: None cas: description: - used when acquiring a lock with a session. If the cas is 0, then 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 the ModifyIndex of that key. + required: false + default: None flags: description: - opaque integer value that can be passed when setting a value. + required: false + default: None + host: + description: + - host of the consul agent defaults to localhost + required: false + default: localhost + port: + description: + - the port on which the consul agent is running + required: false + default: 8500 """ @@ -214,8 +228,8 @@ def main(): argument_spec = dict( cas=dict(required=False), flags=dict(required=False), - host=dict(default='localhost'), key=dict(required=True), + host=dict(default='localhost'), port=dict(default=8500, type='int'), recurse=dict(required=False, type='bool'), retrieve=dict(required=False, default=True), diff --git a/lib/ansible/modules/extras/clustering/consul_session b/lib/ansible/modules/extras/clustering/consul_session index 00f4cae7344..7088dc275ba 100644 --- a/lib/ansible/modules/extras/clustering/consul_session +++ b/lib/ansible/modules/extras/clustering/consul_session @@ -39,35 +39,73 @@ options: node name or session id is required as parameter. required: false choices: ['present', 'absent', 'info', 'node', 'list'] + default: present name: description: - the name that should be associated with the session. This is opaque to Consul and not required. required: false + default: None delay: description: - the optional lock delay that can be attached to the session when it is created. Locks for invalidated sessions ar blocked from being acquired until this delay has expired. default: 15s + required: false node: description: - the name of the node that with which the session will be associated. by default this is the name of the agent. + required: false + default: None datacenter: description: - name of the datacenter in which the session exists or should be created. + required: false + default: None checks: description: - a list of checks that will be used to verify the session health. If all the checks fail, the session will be invalidated and any locks associated with the session will be release and can be acquired once the associated lock delay has expired. + required: false + default: None + host: + description: + - host of the consul agent defaults to localhost + required: false + default: localhost + port: + description: + - the port on which the consul agent is running + required: false + default: 8500 """ EXAMPLES = ''' +- name: register basic session with consul + consul_session: + name: session1 + +- name: register a session with an existing check + consul_session: + name: session_with_check + checks: + - existing_check_name + +- name: register a session with lock_delay + consul_session: + name: session_with_delay + delay: 20 + +- name: retrieve info about session by id + consul_session: id=session_id state=info +- name: retrieve active sessions + consul_session: state=list ''' import sys