Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: check if the cluster is running before exec #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
=================
ansible-pacemaker
=================

Expand Down
15 changes: 15 additions & 0 deletions modules/pacemaker_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down