diff --git a/README.md b/README.md index d743b9a..fb1256c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -================= ansible-pacemaker ================= diff --git a/modules/pacemaker_resource.py b/modules/pacemaker_resource.py index dd0b8ff..dbf911e 100644 --- a/modules/pacemaker_resource.py +++ b/modules/pacemaker_resource.py @@ -74,6 +74,15 @@ ''' +_PCS_CLUSTER_DOWN="Error: cluster is not currently running on this node" + +def get_cluster_status(module): + cmd = "pcs cluster status" + rc, out, err = module.run_command(cmd) + if out in _PCS_CLUSTER_DOWN: + return 'offline' + else: + return 'online' def check_resource_state(module, resource, state): # get resources @@ -120,6 +129,12 @@ def main(): check_mode = module.params['check_mode'] wait_for_resource = module.params['wait_for_resource'] + # First, check if the cluster is running + # Exit if the cluster is down + cluster_state = get_cluster_status(module) + if cluster_state == 'offline': + module.fail_json(msg="The cluster is either offline or not started on the node") + if check_mode: if check_resource_state(module, resource, state): module.exit_json(changed=False,