description:
- The action to take. Either creating OSDs or zapping devices.
required: true
- choices: ['create', 'zap', 'batch', 'list']
+ choices: ['create', 'zap', 'batch', 'prepare', 'activate', 'list']
default: create
data:
description:
required: false
db_vg:
description:
- - If db is a lv, this must be the name of the volume group it belongs to.
+ - If db is a lv, this must be the name of the volume group it belongs to. # noqa E501
- Only applicable if objectstore is 'bluestore'.
required: false
wal:
required: false
wal_vg:
description:
- - If wal is a lv, this must be the name of the volume group it belongs to.
+ - If wal is a lv, this must be the name of the volume group it belongs to. # noqa E501
- Only applicable if objectstore is 'bluestore'.
required: false
crush_device_class:
- Results will be returned in json format.
- Only applicable if action is 'batch'.
required: false
-
+ containerized:
+ description:
+ - Wether or not this is a containerized cluster. The value is
+ assigned or not depending on how the playbook runs.
+ required: false
+ default: None
author:
- Andrew Schoen (@andrewschoen)
data: data-lv
data_vg: data-vg
journal: /dev/sdc1
+ action: create
- name: set up a bluestore osd with a raw device for data
ceph_volume:
objectstore: bluestore
data: /dev/sdc
+ action: create
-- name: set up a bluestore osd with an lv for data and partitions for block.wal and block.db
+
+- name: set up a bluestore osd with an lv for data and partitions for block.wal and block.db # noqa E501
ceph_volume:
objectstore: bluestore
data: data-lv
data_vg: data-vg
db: /dev/sdc1
wal: /dev/sdc2
+ action: create
'''
-from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.basic import AnsibleModule # noqa 4502
def get_data(data, data_vg):
report = module.params['report']
if not batch_devices:
- module.fail_json(msg='batch_devices must be provided if action is "batch"', changed=False, rc=1)
+ module.fail_json(
+ msg='batch_devices must be provided if action is "batch"', changed=False, rc=1) # noqa 4502
cmd = [
'ceph-volume',
module.exit_json(**result)
-def create_osd(module):
+def ceph_volume_cmd(subcommand, containerized, cluster=None):
+ cmd = ['ceph-volume']
+ if cluster:
+ cmd.extend(["--cluster", cluster])
+ cmd.append('lvm')
+ cmd.append(subcommand)
+
+ if containerized:
+ cmd = containerized.split() + cmd
+
+ return cmd
+
+
+def activate_osd(module, containerized=None):
+ subcommand = "activate"
+ cmd = ceph_volume_cmd(subcommand)
+ cmd.append("--all")
+
+ return True
+
+
+def prepare_osd(module):
cluster = module.params['cluster']
objectstore = module.params['objectstore']
data = module.params['data']
wal_vg = module.params.get('wal_vg', None)
crush_device_class = module.params.get('crush_device_class', None)
dmcrypt = module.params['dmcrypt']
+ containerized = module.params.get('containerized', None)
+ subcommand = "prepare"
- cmd = [
- 'ceph-volume',
- '--cluster',
- cluster,
- 'lvm',
- 'create',
- '--%s' % objectstore,
- '--data',
- ]
+ cmd = ceph_volume_cmd(subcommand, containerized, cluster)
+ cmd.extend(["--%s" % objectstore])
+ cmd.append("--data")
data = get_data(data, data_vg)
cmd.append(data)
# check to see if osd already exists
# FIXME: this does not work when data is a raw device
- # support for 'lvm list' and raw devices was added with https://github.com/ceph/ceph/pull/20620 but
+ # support for 'lvm list' and raw devices
+ # was added with https://github.com/ceph/ceph/pull/20620 but
# has not made it to a luminous release as of 12.2.4
- rc, out, err = module.run_command(["ceph-volume", "lvm", "list", data], encoding=None)
+ ceph_volume_list_cmd = ["ceph-volume", "lvm", "list", data]
+ if containerized:
+ ceph_volume_list_cmd = containerized.split() + ceph_volume_list_cmd
+
+ rc, out, err = module.run_command(ceph_volume_list_cmd, encoding=None)
if rc == 0:
- result["stdout"] = "skipped, since {0} is already used for an osd".format(data)
+ result["stdout"] = "skipped, since {0} is already used for an osd".format( # noqa E501
+ data)
result['rc'] = 0
module.exit_json(**result)
def run_module():
module_args = dict(
cluster=dict(type='str', required=False, default='ceph'),
- objectstore=dict(type='str', required=False, choices=['bluestore', 'filestore'], default='bluestore'),
- action=dict(type='str', required=False, choices=['create', 'zap', 'batch', 'list'], default='create'),
+ objectstore=dict(type='str', required=False, choices=[
+ 'bluestore', 'filestore'], default='bluestore'),
+ action=dict(type='str', required=False, choices=[
+ 'create', 'zap', 'batch', 'prepare', 'activate', 'list'], default='create'), # noqa 4502
data=dict(type='str', required=False),
data_vg=dict(type='str', required=False),
journal=dict(type='str', required=False),
journal_size=dict(type='str', required=False, default="5120"),
block_db_size=dict(type='str', required=False, default="-1"),
report=dict(type='bool', required=False, default=False),
+ containerized=dict(type='str', required=False, default=False),
)
module = AnsibleModule(
action = module.params['action']
if action == "create":
- create_osd(module)
+ prepare_osd(module)
+ activate_osd(module)
+ elif action == "prepare":
+ prepare_osd(module)
+ elif action == "activate":
+ activate_osd(module)
elif action == "zap":
zap_devices(module)
elif action == "batch":
elif action == "list":
_list(module)
- module.fail_json(msg='State must either be "present" or "absent".', changed=False, rc=1)
+ module.fail_json(
+ msg='State must either be "present" or "absent".', changed=False, rc=1)
def main():