From: Andrew Schoen Date: Mon, 1 Oct 2018 17:51:47 +0000 (-0500) Subject: ceph-volume: make the batch action idempotent X-Git-Tag: v3.2.0beta4~14 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5ee305d1a02f9cf0196b85ab277e408319e4b24c;p=ceph-ansible.git ceph-volume: make the batch action idempotent The command is run with --report first to see if any OSDs will be created or not. If they will be, then the command is run. If not, then changed is set to False and the module exits. Signed-off-by: Andrew Schoen --- diff --git a/library/ceph_volume.py b/library/ceph_volume.py index f59b70d11..f05bab57c 100644 --- a/library/ceph_volume.py +++ b/library/ceph_volume.py @@ -1,6 +1,7 @@ #!/usr/bin/python import datetime import json +import copy ANSIBLE_METADATA = { @@ -257,11 +258,10 @@ def batch(module): if objectstore == "bluestore" and block_db_size != "-1": cmd.extend(["--block-db-size", block_db_size]) - if report: - cmd.extend([ - "--report", - "--format=json", - ]) + report_flags = [ + "--report", + "--format=json", + ] cmd.extend(batch_devices) @@ -281,11 +281,23 @@ def batch(module): startd = datetime.datetime.now() - rc, out, err = module.run_command(cmd, encoding=None) + report_cmd = copy.copy(cmd) + report_cmd.extend(report_flags) + + rc, out, err = module.run_command(report_cmd, encoding=None) + report_result = json.loads(out) + if not report: + rc, out, err = module.run_command(cmd, encoding=None) + else: + cmd = report_cmd endd = datetime.datetime.now() delta = endd - startd + changed = True + if not report: + changed = report_result['changed'] + result = dict( cmd=cmd, stdout=out.rstrip(b"\r\n"), @@ -294,7 +306,7 @@ def batch(module): start=str(startd), end=str(endd), delta=str(delta), - changed=True, + changed=changed, ) if rc != 0: