def main(): argument_spec = cassandra_common_argument_spec() module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False) cmd = 'truncatehints' n = NodeToolCommandSimple(module, cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "nodetool truncatehints executed successfully" module.exit_json(**result) else: result['rc'] = rc result['changed'] = False result['msg'] = "nodetool truncatehints did not execute successfully" module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( value=dict(type='float', required=True) ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) set_cmd = "settraceprobability {0}".format(module.params['value']) get_cmd = "gettraceprobability" value = module.params['value'] n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err get_response = "Current trace probability: {0}".format(value) if get_response == out: if rc != 0: result['changed'] = False module.fail_json(name=get_cmd, msg="get command failed", **result) else: if module.check_mode: result['changed'] = True else: (rc, out, err) = n.set_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="set command failed", **result) else: result['changed'] = True module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( down=dict(type='int', default=0, aliases=["d"]), poll=dict(type='int', default=1), interval=dict(type='int', default=30) ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) down = module.params['down'] debug = module.params['debug'] cluster_status, cluster_status_list, iterations, \ return_codes, stdout_list, stderr_list, down_running_total \ = nodetool_status_poll(module) result = {} result['cluster_status'] = cluster_status result['iterations'] = iterations if debug: result['cluster_status_list'] = cluster_status_list result['return_codes'] = return_codes if stderr_list: result['stderr_list'] = stderr_list if stdout_list: result['stdout_list'] = stdout_list # Needs rethink if return_codes[-1] == 0: # Last execution successful if down_running_total == 0: result['msg'] = "All nodes are in an UP/NORMAL state" else: if down_running_total > down: result['msg'] = "Too many nodes are in a DOWN state" module.fail_json(**result) else: result['msg'] = "Down nodes are within the tolerated level" else: result['msg'] = "nodetool error: {0}".format(stderr_list[-1]) result['rc'] = return_codes[-1] module.fail_json(**result) # Everything is good module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(uuid=dict(type='str', aliases=['is']), poll=dict(type='int', default=1), interval=dict(type='int', default=30)) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) uuid = module.params['uuid'] debug = module.params['debug'] schema_status, cluster_schema_list, iterations, \ return_codes, stdout_list, stderr_list, schema_count_total \ = nodetool_status_poll(module) result = {} result['schema_status'] = schema_status if iterations > 1: result['iterations'] = iterations if debug: result['cluster_schema_list'] = cluster_schema_list result['return_codes'] = return_codes if stderr_list: result['stderr_list'] = stderr_list if stdout_list: result['stdout_list'] = stdout_list # Needs rethink if return_codes[-1] == 0: # Last execution successful if schema_count_total == 1 and uuid in schema_status.keys(): result[ 'msg'] = "The cluster has reached consensus with the expected version" elif schema_count_total == 1: result['msg'] = "The cluster has reached schema consensus" else: result[ 'msg'] = "The cluster has not reached consensus on the schema" module.fail_json(**result) else: result['msg'] = "nodetool error: {0}".format(stderr_list[-1]) result['rc'] = return_codes[-1] module.fail_json(**result) # Everything is good module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(keyspace=dict(type='str', default=None, required=False, no_log=False), table=dict(type='raw', default=None, required=False), extended=dict(type='bool', default=False, required=False, aliases=['e'])) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) cmd = 'verify' n = NodeToolCommand(module, cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "nodetool verify executed successfully" module.exit_json(**result) else: result['rc'] = rc result['changed'] = False result['msg'] = "nodetool verify did not execute successfully" module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(keyspace=dict(type='str', default=None, required=False), table=dict(type='raw', default=None, required=False), num_jobs=dict(type='int', default=2, aliases=['j'], required=False)) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) cmd = 'upgradesstables' n = NodeToolCommandKeyspaceTableNumJobs(module, cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "nodetool upgradesstables executed successfully" module.exit_json(**result) else: result['rc'] = rc result['changed'] = False result['msg'] = "nodetool upgradesstables did not execute successfully" module.exit_json(**result)
def main(): reload_choices = ['localschema', 'seeds', 'ssl', 'triggers'] argument_spec = cassandra_common_argument_spec() argument_spec.update( reload=dict(type='str', choices=reload_choices, required=True) ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) cmd = "reload{0}".format(module.params['reload']) n = NodeToolCommandSimple(module, cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "nodetool {0} executed successfully".format(cmd) module.exit_json(**result) else: result['rc'] = rc result['changed'] = False result['msg'] = "nodetool {0} did not execute successfully".format(cmd) module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(keyspace=dict(type='str', no_log=False), table=dict(type='str'), granularity=dict(type='str', default="ROW", choices=["ROW", "CELL"]), jobs=dict(type='int', default=2)) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) cmd = 'garbagecollect' n = NodeToolCommand(module, cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "nodetool garbagecollect executed successfully" else: result['rc'] = rc result['changed'] = False result['msg'] = "nodetool garbagecollect did not execute successfully" module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) cmd = 'stopdaemon' n = NodeToolCommandSimple(module, cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.run_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "nodetool stopdaemon executed successfully" module.exit_json(**result) elif rc == 2 and out == "Cassandra has shutdown.": # 2.2 behaves a little differently result['changed'] = True result['msg'] = "nodetool stopdaemon executed successfully" module.exit_json(**result) else: result['rc'] = rc result['changed'] = False result['msg'] = "nodetool stopdaemon did not execute successfully" module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( ip_address=dict(type='str', required=True), debug=dict(type='bool', default=False), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) ip_address = module.params['ip_address'] cmd = 'assassinate -- {0}'.format(ip_address) n = NodeToolCommandSimple(module, cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "nodetool assassinate executed successfully for endpoint: {0}".format(ip_address) module.exit_json(**result) else: result['msg'] = "nodetool assassinate did not execute successfully rc: {0}".format(rc) module.fail_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( state=dict(required=True, choices=['enabled', 'disabled'])) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) status_cmd = 'statushandoff' enable_cmd = 'enablehandoff' disable_cmd = 'disablehandoff' status_active = ['Hinted handoff is running', 'running'] status_inactive = ['Hinted handoff is not running', 'not running'] n = NodeTool3PairCommand(module, status_cmd, enable_cmd, disable_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.status_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if module.params['state'] == "disabled": if rc != 0: module.fail_json(name=status_cmd, msg="status command failed", **result) if module.check_mode: if out in status_active: module.exit_json(changed=True, msg="check mode", **result) else: module.exit_json(changed=False, msg="check mode", **result) if out in status_active: (rc, out, err) = n.disable_command() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: module.fail_json(name=disable_cmd, msg="disable command failed", **result) else: result['changed'] = True elif module.params['state'] == "enabled": if rc != 0: module.fail_json(name=status_cmd, msg="status command failed", **result) if module.check_mode: if out in status_inactive: module.exit_json(changed=True, msg="check mode", **result) else: module.exit_json(changed=False, msg="check mode", **result) if out in status_inactive: (rc, out, err) = n.enable_command() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc is not None and rc != 0: module.fail_json(name=enable_cmd, msg="enable command failed", **result) else: result['changed'] = True module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(debug=dict(type='bool', default=False), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) debug = module.params['debug'] result = {} cmd = "ring" rc = None out = '' err = '' result = {} n = NodeToolCommandSimple(module, cmd) (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: if module.params['host'] in out: # host is still in ring cmd = "decommission" n = NodeToolCommandSimple(module, cmd) if not module.check_mode: (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "decommission command succeeded" else: result['msg'] = "decommission command failed" result['rc'] = rc module.fail_json(**result) else: result['changed'] = True result['msg'] = "decommission command succeeded" else: result['changed'] = False result['msg'] = "Node appears to be already decommissioned" module.exit_json(**result) else: result['msg'] = "decommission command failed" result['rc'] = rc module.fail_json(**result) # Everything is good module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(keyspace=dict(type='str', required=True), table=dict(type='str', required=True), min=dict(type='int', required=True), max=dict(type='int', required=True)) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) keyspace = module.params['keyspace'] table = module.params['table'] min = module.params['min'] max = module.params['max'] set_cmd = "setcompactionthreshold {0} {1} {2} {3}".format( keyspace, table, min, max) get_cmd = "getcompactionthreshold {0} {1}".format(keyspace, table) n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err get_response = "Current compaction thresholds for {0}/{1}: \n min = {2}, max = {3}".format( keyspace, table, min, max) if get_response == out: if rc != 0: result['changed'] = False module.fail_json(name=get_cmd, msg="get command failed", **result) else: if module.check_mode: result['changed'] = True else: (rc, out, err) = n.set_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="set command failed", **result) else: result['changed'] = True module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( host_id=dict(type='str', required=True), force=dict(type='bool', default=False), debug=dict(type='bool', default=False), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) host_id = module.params['host_id'] force = module.params['force'] if not valid_uuid(host_id): module.fail_json(msg="host_id is not a valid uuid") result = {} cmd = "status" rc = None out = '' err = '' result = {} n = NodeToolCommandSimple(module, cmd) (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: if host_id in out: # host is still in ring if force: cmd = "removenode -- force {0}".format(host_id) else: cmd = "removenode -- {0}".format(host_id) n = NodeToolCommandSimple(module, cmd) if not module.check_mode: (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "removenode command succeeded" else: result['msg'] = "removenode command failed" result['rc'] = rc module.fail_json(**result) else: result['changed'] = True result['msg'] = "removenode command succeeded" else: result['changed'] = False result['msg'] = "host_id does not exist in the cluster" module.exit_json(**result) else: result['msg'] = "removenode command failed" result['rc'] = rc module.fail_json(**result) # Everything is good module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(compact=dict(default=True, type='bool')) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) status_cmd = 'compactionstats' enable_cmd = 'compact' disable_cmd = 'stop' status_inactive = 'pending tasks: 0' n = NodeTool3PairCommand(module, status_cmd, enable_cmd, disable_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.status_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if module.params['compact'] is False: if rc != 0: module.fail_json(name=status_cmd, msg="{0} command failed".format(status_cmd), **result) if module.check_mode: if out != status_inactive: module.exit_json(changed=True, msg="compaction stopped (check mode)", **result) else: module.exit_json(changed=False, msg="compaction is not running", **result) if out != status_inactive: (rc, out, err) = n.disable_command() result['msg'] = "compaction stopped" result['changed'] = True if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: module.fail_json(name=disable_cmd, msg="{0} command failed".format(disable_cmd), **result) else: result['msg'] = "compaction is not running" result['changed'] = False elif module.params['compact'] is True: if rc != 0: module.fail_json(name=status_cmd, msg="{0} command failed".format(status_cmd), **result) if module.check_mode: if out == status_inactive: module.exit_json(changed=True, msg="compaction started (check mode)", **result) else: module.exit_json(changed=False, msg="compaction is already running", **result) if out == status_inactive: (rc, out, err) = n.enable_command() result['msg'] = "compaction started" result['changed'] = True if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc is not None and rc != 0: module.fail_json(name=enable_cmd, msg="{0} command failed".format(enable_cmd), **result) else: result['msg'] = "compaction is already running" result['changed'] = False module.exit_json(**result)
def main(): cache_choices = ["counter", "key", "row"] argument_spec = cassandra_common_argument_spec() argument_spec.update(cache=dict(type='str', required=True, choices=cache_choices), debug=dict(type='bool', default=False), fake_counter=dict(type='bool', default=False)) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) result = {} cmd = "info" n = NodeToolCommandSimple(module, cmd) (rc, out, err) = n.run_command() out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: cache = module.params['cache'] cmd = 'invalidate{0}cache'.format(cache) fake_counter = module.params['fake_counter'] cache_info = parse_cache_info(out, module, fake_counter) if cache == "key" and cache_info['key_cache_entries'] > 0 or cache == "row" and cache_info['row_cache_entries'] > 0 \ or cache == "counter" and cache_info['counter_cache_entries'] > 0: n = NodeToolCommandSimple(module, cmd) rc = None out = '' err = '' result = {} if module.check_mode is False: (rc, out, err) = n.run_command() else: rc = 0 out = out.strip() err = err.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc == 0: result['changed'] = True result['msg'] = "The {0} cache was invalidated".format(cache) else: result['msg'] = "Failed invalidating the {0} cache".format( cache) module.fail_json(**result) else: result['msg'] = "The {0} cache is empty".format(cache) result['changed'] = False else: result['msg'] = "Failed getting cache info" module.fail_json(**result) module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( value=dict(type='int', required=True) ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) set_cmd = "setbatchlogreplaythrottle {0}".format(module.params['value']) get_cmd = "getbatchlogreplaythrottle" value = module.params['value'] n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err get_response = "Batchlog replay throttle: {0} KB/s".format(value) if get_response == out: if rc != 0: result['changed'] = False module.fail_json(name=get_cmd, msg="{0} command failed".format(get_cmd), **result) else: result['changed'] = False result['msg'] = "Batch log replay throttle is already {0} KB/s".format(value) else: if module.check_mode: result['changed'] = True result['msg'] = "Batch log replay throttle updated" else: (rc, out, err) = n.set_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="{0} command failed".format(set_cmd), **result) else: result['changed'] = True result['msg'] = "Batch log replay throttle updated" module.exit_json(**result)
def main(): timeout_type_choices = ['read', 'range', 'write', 'counterwrite', 'cascontention', 'truncate', 'internodeconnect', 'internodeuser', 'internodestreaminguser', 'misc'] argument_spec = cassandra_common_argument_spec() argument_spec.update( timeout=dict(type='int', required=True), timeout_type=dict(type='str', choices=timeout_type_choices, default='read') ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) timeout = module.params['timeout'] timeout_type = module.params['timeout_type'] set_cmd = "settimeout {0} {1}".format(timeout_type, timeout) get_cmd = "gettimeout {0}".format(timeout_type) n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err get_response = "Current timeout for type {0}: {1} ms".format(timeout_type, timeout) if get_response == out: if rc != 0: module.fail_json(name=get_cmd, msg="get command failed", **result) result['changed'] = False result['msg'] = "{0} timeout unchanged".format(timeout_type) else: if module.check_mode: result['changed'] = True else: (rc, out, err) = n.set_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="set command failed", **result) else: result['changed'] = True result['msg'] = "{0} timeout changed".format(timeout_type) module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(keyspace=dict(type='str', required=True), table=dict(type='list', elements='str', required=True), state=dict(required=True, choices=['enabled', 'disabled'])) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=False, ) keyspace = module.params['keyspace'] table = ' '.join(module.params['table']) enable_cmd = 'enableautocompaction {0} {1}'.format(keyspace, table) disable_cmd = 'disableautocompaction {0} {1}'.format(keyspace, table) n = NodeTool2PairCommand(module, enable_cmd, disable_cmd) rc = None out = '' err = '' result = {} result['changed'] = False # We don't know if this has changed or not if module.params['state'] == "enabled": (rc, out, err) = n.enable_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['msg'] = "enable command failed" module.fail_json(name=enable_cmd, **result) else: result['changed'] = True elif module.params['state'] == "disabled": (rc, out, err) = n.disable_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['msg'] = "disable command failed" module.fail_json(name=disable_cmd, **result) else: result['changed'] = True module.exit_json(**result)
def main(): cs_choices = [ "AntiEntropyStage", "CounterMutationStage", "GossipStage", "ImmediateStage", "InternalResponseStage", "MigrationStage", "MiscStage", "MutationStage", "ReadStage", "RequestResponseStage", "TracingStage", "ViewMutationStage" ] argument_spec = cassandra_common_argument_spec() argument_spec.update(concurrency_type=dict( type='str', choices=["default", "compactors", "viewbuilders"], default="default"), concurrency_stage=dict(type='str', choices=cs_choices), value=dict(type='int', required=True)) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[["concurrency_type", "default", ["concurrency_stage"]]]) concurrency_type = module.params['concurrency_type'] concurrency_stage = module.params['concurrency_stage'] value = module.params['value'] if concurrency_type != "default": get_cmd = "{0}{1}".format("getconcurrent", concurrency_type) set_cmd = "{0}{1} -- {2}".format("setconcurrent", concurrency_type, value) else: get_cmd = "{0} -- {1} ".format("getconcurrency", concurrency_stage) set_cmd = "{0} -- {1} {2}".format("setconcurrency", concurrency_stage, value) n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err # Matches the last int in the output try: current_value = out.split()[-1:][0] if current_value.isdigit(): current_value = int(current_value) else: raise IndexError except IndexError as ie: module.fail_json(msg="Failure parsing {0} output: {1}".format( get_cmd, str(ie)), **result) if current_value == value: if rc != 0: # should probably move this above result['changed'] = False module.fail_json(name=get_cmd, msg="get command failed", **result) result['msg'] = "Configured value is already {0}".format(value) else: if module.check_mode: result['changed'] = True if concurrency_type != "default": result['msg'] = "{0} updated to {1}".format( concurrency_type, value) else: result['msg'] = "{0}/{1} updated to {2}".format( concurrency_type, concurrency_stage, value) else: (rc, out, err) = n.set_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="set command failed", **result) else: result['changed'] = True if concurrency_type != "default": result['msg'] = "{0} updated to {1}".format( concurrency_type, value) else: result['msg'] = "{0}/{1} updated to {2}".format( concurrency_type, concurrency_stage, value) module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( state=dict(type='str', choices=['enabled', 'disabled', 'reset'], default='enabled'), log_dir=dict(type='str', aliases=['path']), archive_command=dict(type='str'), roll_cycle=dict(type='str', choices=['MINUTELY', 'HOURLY', 'DAILY'], default='HOURLY'), blocking=dict(type='bool', default=True, aliases=['block']), max_log_size=dict(type='int', default=17179869184), max_queue_weight=dict(type='int', default=268435456), max_archive_retries=dict(type='int', default=10), debug=dict(type='bool', default=False), ) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_if=[("state", "enabled", ["log_dir"])]) status_cmd = 'getfullquerylog' enable_cmd = 'enablefullquerylog' disable_cmd = 'disablefullquerylog' reset_cmd = 'resetfullquerylog' archive_command = module.params['archive_command'] additional_args = "" if module.params['state'] == "enabled": if archive_command is not None: additional_args = "--archive-command \"{0}\"".format( escape_param(archive_command)) additional_args += " --blocking {0}".format( str(module.params['blocking'])) additional_args += " --max-archive-retries {0}".format( module.params['max_archive_retries']) additional_args += " --max-log-size {0}".format( module.params['max_log_size']) additional_args += " --max-queue-weight {0}".format( module.params['max_queue_weight']) additional_args += " --roll-cycle {0}".format( module.params['roll_cycle']) additional_args += " --path {0}".format( escape_param(module.params['log_dir'])) n = NodeTool4PairCommand(module, status_cmd, enable_cmd, disable_cmd, reset_cmd, additional_args) rc = None out = '' err = '' result = {} (rc, out, err) = n.status_command() # Parse the output into a dict out = out.strip() fullquerylog_config = parse_getfullquerylog(out) if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err result['additional_args'] = additional_args if module.params['state'] == "disabled": if rc != 0: module.fail_json(name=status_cmd, msg="status command failed", **result) if module.check_mode: if fullqueryconfig_diff(fullquerylog_config, module): result['changed'] = True result['msg'] = "check mode" result['fullquerylog_config'] = fullquerylog_config else: result['changed'] = False result['msg'] = "check mode" result['fullquerylog_config'] = fullquerylog_config if fullquerylog_config['enabled']: (rc, out, err) = n.disable_command() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: module.fail_json(name=disable_cmd, msg="disable command failed", **result) else: result['changed'] = True result['msg'] = "fullquerylog disabled" result['fullquerylog_config'] = fullquerylog_config elif module.params['state'] == "enabled": if rc != 0: module.fail_json(name=status_cmd, msg="status command failed", **result) if module.check_mode: if fullqueryconfig_diff(fullquerylog_config, module): result['changed'] = True result['msg'] = "check mode" result['fullquerylog_config'] = fullquerylog_config else: result['changed'] = False result['msg'] = "check mode" result['fullquerylog_config'] = fullquerylog_config else: if fullqueryconfig_diff(fullquerylog_config, module): (rc, out, err) = n.enable_command() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc is not None and rc != 0: module.fail_json(name=enable_cmd, msg="enable command failed", **result) result['changed'] = True result['msg'] = 'fullquerylog reconfigured' result['fullquerylog_config'] = fullquerylog_config else: result['changed'] = False result['msg'] = 'fullquerylog state unchanged' result['fullquerylog_config'] = fullquerylog_config elif module.params['state'] == "reset": if rc != 0: module.fail_json(name=reset_cmd, msg="resetfullquerylog command failed", **result) if module.check_mode: module.exit_json(changed=True, msg="resetfullquerylog succeeded check mode", **result) else: (rc, out, err) = n.reset_command() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc is not None and rc != 0: module.fail_json(name=reset_cmd, msg="resetfullquerylog command failed", **result) else: result['changed'] = True result['msg'] = 'resetfullquerylog succeeded' result['fullquerylog_config'] = fullquerylog_config module.exit_json(**result)