2018-03-23 21:57:28 +08:00
|
|
|
|
|
|
|
from ansible.plugins.action import ActionBase
|
2018-10-16 23:20:54 +08:00
|
|
|
from distutils.version import LooseVersion
|
2018-11-14 00:22:44 +08:00
|
|
|
from ansible.module_utils.six import string_types
|
|
|
|
from ansible.errors import AnsibleUndefinedVariable
|
2018-03-23 21:57:28 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
from __main__ import display
|
|
|
|
except ImportError:
|
|
|
|
from ansible.utils.display import Display
|
|
|
|
display = Display()
|
|
|
|
|
2018-05-03 05:06:08 +08:00
|
|
|
try:
|
|
|
|
import notario
|
|
|
|
except ImportError:
|
2018-10-11 23:59:31 +08:00
|
|
|
msg = "The python-notario library is missing. Please install it on the node you are running ceph-ansible to continue." # noqa E501
|
2018-05-03 05:06:08 +08:00
|
|
|
display.error(msg)
|
|
|
|
raise SystemExit(msg)
|
|
|
|
|
2018-10-16 23:20:54 +08:00
|
|
|
if LooseVersion(notario.__version__) < LooseVersion("0.0.13"):
|
|
|
|
msg = "The python-notario libary has an incompatible version. Version >= 0.0.13 is needed, current version: %s" % notario.__version__
|
|
|
|
display.error(msg)
|
|
|
|
raise SystemExit(msg)
|
|
|
|
|
2018-05-03 05:06:08 +08:00
|
|
|
from notario.exceptions import Invalid
|
|
|
|
from notario.validators import types, chainable, iterables
|
|
|
|
from notario.decorators import optional
|
|
|
|
from notario.store import store as notario_store
|
|
|
|
|
2018-03-23 21:57:28 +08:00
|
|
|
|
2018-11-27 06:29:50 +08:00
|
|
|
CEPH_RELEASES = ['jewel', 'kraken', 'luminous', 'mimic', 'nautilus']
|
2018-05-04 05:27:44 +08:00
|
|
|
|
|
|
|
|
2018-03-23 21:57:28 +08:00
|
|
|
class ActionModule(ActionBase):
|
|
|
|
|
|
|
|
def run(self, tmp=None, task_vars=None):
|
2018-04-12 04:03:53 +08:00
|
|
|
# we must use vars, since task_vars will have un-processed variables
|
2018-11-14 00:22:44 +08:00
|
|
|
host_vars = self.expand_all_jinja2_templates(task_vars['vars'])
|
2018-04-12 04:03:53 +08:00
|
|
|
host = host_vars['ansible_hostname']
|
2018-03-23 21:57:28 +08:00
|
|
|
mode = self._task.args.get('mode', 'permissive')
|
|
|
|
|
2018-10-11 23:59:31 +08:00
|
|
|
self._supports_check_mode = False # XXX ?
|
2018-04-12 04:03:53 +08:00
|
|
|
self._supports_async = True
|
2018-03-23 21:57:28 +08:00
|
|
|
|
|
|
|
result = {}
|
|
|
|
result['_ansible_verbose_always'] = True
|
|
|
|
|
2018-04-12 04:03:53 +08:00
|
|
|
try:
|
2018-05-01 00:04:42 +08:00
|
|
|
notario_store["groups"] = host_vars["groups"]
|
2018-10-11 23:59:31 +08:00
|
|
|
notario_store["containerized_deployment"] = host_vars["containerized_deployment"] # noqa E501
|
2018-04-12 04:03:53 +08:00
|
|
|
notario.validate(host_vars, install_options, defined_keys=True)
|
|
|
|
|
2018-10-31 23:25:26 +08:00
|
|
|
if host_vars["ceph_origin"] == "repository" and not host_vars["containerized_deployment"]:
|
2018-10-11 23:59:31 +08:00
|
|
|
notario.validate(
|
|
|
|
host_vars, ceph_origin_repository, defined_keys=True)
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
if host_vars["ceph_repository"] == "community":
|
2018-10-11 23:59:31 +08:00
|
|
|
notario.validate(
|
|
|
|
host_vars, ceph_repository_community, defined_keys=True) # noqa E501
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
if host_vars["ceph_repository"] == "rhcs":
|
2018-10-11 23:59:31 +08:00
|
|
|
notario.validate(
|
|
|
|
host_vars, ceph_repository_rhcs, defined_keys=True)
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
if host_vars["ceph_repository"] == "dev":
|
2018-10-11 23:59:31 +08:00
|
|
|
notario.validate(
|
|
|
|
host_vars, ceph_repository_dev, defined_keys=True)
|
2018-04-12 04:03:53 +08:00
|
|
|
|
2019-01-21 16:08:39 +08:00
|
|
|
if host_vars["ceph_repository"] == "custom":
|
|
|
|
notario.validate(host_vars, ceph_repository_custom, defined_keys=True)
|
|
|
|
|
2018-10-11 23:59:31 +08:00
|
|
|
# store these values because one must be defined
|
|
|
|
# and the validation method
|
2018-04-19 02:29:25 +08:00
|
|
|
# will need access to all three through the store
|
2018-10-11 23:59:31 +08:00
|
|
|
notario_store["monitor_address"] = host_vars.get(
|
|
|
|
"monitor_address", None)
|
|
|
|
notario_store["monitor_address_block"] = host_vars.get(
|
|
|
|
"monitor_address_block", None)
|
|
|
|
notario_store["monitor_interface"] = host_vars.get(
|
|
|
|
"monitor_interface", None)
|
2018-04-19 02:29:25 +08:00
|
|
|
|
2018-05-01 01:59:07 +08:00
|
|
|
if host_vars["mon_group_name"] in host_vars["group_names"]:
|
|
|
|
notario.validate(host_vars, monitor_options, defined_keys=True)
|
2018-04-19 02:29:25 +08:00
|
|
|
|
2018-10-11 23:59:31 +08:00
|
|
|
notario_store["radosgw_address"] = host_vars.get(
|
|
|
|
"radosgw_address", None)
|
|
|
|
notario_store["radosgw_address_block"] = host_vars.get(
|
|
|
|
"radosgw_address_block", None)
|
|
|
|
notario_store["radosgw_interface"] = host_vars.get(
|
|
|
|
"radosgw_interface", None)
|
2018-05-01 00:04:42 +08:00
|
|
|
|
2018-05-01 01:59:07 +08:00
|
|
|
if host_vars["rgw_group_name"] in host_vars["group_names"]:
|
2018-05-01 00:04:42 +08:00
|
|
|
notario.validate(host_vars, rados_options, defined_keys=True)
|
|
|
|
|
2018-04-24 00:06:22 +08:00
|
|
|
# validate osd scenario setup
|
2018-05-01 02:08:49 +08:00
|
|
|
if host_vars["osd_group_name"] in host_vars["group_names"]:
|
|
|
|
notario.validate(host_vars, osd_options, defined_keys=True)
|
|
|
|
notario_store['osd_objectstore'] = host_vars["osd_objectstore"]
|
2018-04-24 00:06:22 +08:00
|
|
|
|
2018-10-12 00:01:10 +08:00
|
|
|
if host_vars.get("devices"):
|
2018-10-11 23:59:31 +08:00
|
|
|
notario.validate(
|
2018-10-12 00:01:10 +08:00
|
|
|
host_vars, lvm_batch_scenario, defined_keys=True)
|
|
|
|
elif notario_store['osd_objectstore'] == 'filestore':
|
|
|
|
notario.validate(
|
|
|
|
host_vars, lvm_filestore_scenario, defined_keys=True) # noqa E501
|
|
|
|
elif notario_store['osd_objectstore'] == 'bluestore':
|
|
|
|
notario.validate(
|
|
|
|
host_vars, lvm_bluestore_scenario, defined_keys=True) # noqa E501
|
2018-04-24 00:06:22 +08:00
|
|
|
|
2018-04-12 04:03:53 +08:00
|
|
|
except Invalid as error:
|
2018-10-11 23:59:31 +08:00
|
|
|
display.vvvv("Notario Failure: %s" % str(error))
|
|
|
|
msg = "[{}] Validation failed for variable: {}".format(
|
|
|
|
host, error.path[0])
|
|
|
|
display.error(msg)
|
|
|
|
reason = "[{}] Reason: {}".format(host, error.reason)
|
2018-05-02 00:21:48 +08:00
|
|
|
try:
|
2019-04-23 22:04:27 +08:00
|
|
|
if "schema is missing" not in str(error):
|
2018-10-10 04:47:40 +08:00
|
|
|
for i in range(0, len(error.path)):
|
|
|
|
if i == 0:
|
|
|
|
given = "[{}] Given value for {}".format(
|
|
|
|
host, error.path[0])
|
|
|
|
else:
|
|
|
|
given = given + ": {}".format(error.path[i])
|
2018-11-17 08:28:54 +08:00
|
|
|
if given:
|
|
|
|
display.error(given)
|
2018-05-02 00:21:48 +08:00
|
|
|
else:
|
|
|
|
given = ""
|
|
|
|
reason = "[{}] Reason: {}".format(host, error.message)
|
|
|
|
except KeyError:
|
|
|
|
given = ""
|
|
|
|
display.error(reason)
|
2018-04-12 04:03:53 +08:00
|
|
|
result['failed'] = mode == 'strict'
|
2018-11-17 08:28:54 +08:00
|
|
|
result['msg'] = "\n".join([s for s in (msg, reason, given) if len(s) > 0])
|
|
|
|
result['stderr_lines'] = result['msg'].split('\n')
|
|
|
|
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
return result
|
2018-03-23 21:57:28 +08:00
|
|
|
|
2018-11-14 00:22:44 +08:00
|
|
|
def expand_all_jinja2_templates(self, variables):
|
|
|
|
for k, v in variables.items():
|
|
|
|
try:
|
|
|
|
if self._templar.is_template(v):
|
|
|
|
variables[k] = self.expand_jinja2_template(v)
|
|
|
|
except AnsibleUndefinedVariable as e:
|
|
|
|
variables[k] = u"VARIABLE IS NOT DEFINED!"
|
|
|
|
|
|
|
|
return variables
|
|
|
|
|
|
|
|
def expand_jinja2_template(self, var):
|
|
|
|
expanded_var = self._templar.template(var, convert_bare=True,
|
|
|
|
fail_on_undefined=True)
|
|
|
|
if expanded_var == var:
|
|
|
|
if not isinstance(expanded_var, string_types):
|
|
|
|
raise AnsibleUndefinedVariable
|
|
|
|
expanded_var = self._templar.template("{{%s}}" % expanded_var,
|
|
|
|
convert_bare=True,
|
|
|
|
fail_on_undefined=True)
|
|
|
|
return expanded_var
|
|
|
|
|
2018-03-23 21:57:28 +08:00
|
|
|
# Schemas
|
|
|
|
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
def osd_objectstore_choices(value):
|
2018-10-11 23:59:31 +08:00
|
|
|
assert value in [
|
|
|
|
'bluestore', 'filestore'], "osd_objectstore must be either 'bluestore' or 'filestore'" # noqa E501
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
def ceph_origin_choices(value):
|
2018-05-03 05:11:51 +08:00
|
|
|
if not notario_store["containerized_deployment"]:
|
2018-10-11 23:59:31 +08:00
|
|
|
assert value in ['repository', 'distro',
|
|
|
|
'local'], "ceph_origin must be either 'repository', 'distro' or 'local'" # noqa E501
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
def ceph_repository_choices(value):
|
2019-03-23 03:03:15 +08:00
|
|
|
msg = "ceph_repository must be either 'community', 'rhcs', 'dev', 'custom' or 'uca'"
|
|
|
|
assert value in ['community', 'rhcs', 'dev', 'custom', 'uca'], msg
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
def ceph_repository_type_choices(value):
|
2018-10-11 23:59:31 +08:00
|
|
|
assert value in [
|
|
|
|
'cdn', 'iso'], "ceph_repository_type must be either 'cdn' or 'iso'"
|
2018-04-12 04:03:53 +08:00
|
|
|
|
|
|
|
|
2018-04-19 02:29:25 +08:00
|
|
|
def validate_monitor_options(value):
|
|
|
|
"""
|
|
|
|
Either monitor_address, monitor_address_block or monitor_interface must
|
|
|
|
be defined.
|
|
|
|
"""
|
|
|
|
monitor_address_given = notario_store["monitor_address"] != "0.0.0.0"
|
2018-10-11 23:59:31 +08:00
|
|
|
monitor_address_block_given = notario_store["monitor_address_block"] != "subnet" # noqa E501
|
2018-04-19 02:29:25 +08:00
|
|
|
monitor_interface_given = notario_store["monitor_interface"] != "interface"
|
|
|
|
|
2018-10-11 23:59:31 +08:00
|
|
|
msg = "Either monitor_address, monitor_address_block or monitor_interface must be provided" # noqa E501
|
2018-04-19 02:29:25 +08:00
|
|
|
|
2018-10-11 23:59:31 +08:00
|
|
|
assert any([monitor_address_given, monitor_address_block_given,
|
|
|
|
monitor_interface_given]), msg
|
2018-04-24 00:06:22 +08:00
|
|
|
|
|
|
|
|
2018-10-29 01:37:21 +08:00
|
|
|
def validate_dmcrypt_bool_value(value):
|
2018-10-11 23:59:31 +08:00
|
|
|
assert value in ["true", True, "false",
|
|
|
|
False], "dmcrypt can be set to true/True or false/False (default)"
|
2018-10-29 01:37:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
def validate_osd_auto_discovery_bool_value(value):
|
2018-10-11 23:59:31 +08:00
|
|
|
assert value in ["true", True, "false",
|
|
|
|
False], "osd_auto_discovery can be set to true/True or false/False (default)"
|
2018-10-29 01:37:21 +08:00
|
|
|
|
|
|
|
|
2018-04-24 00:06:22 +08:00
|
|
|
def validate_objectstore(value):
|
2018-10-11 23:59:31 +08:00
|
|
|
assert value in [
|
|
|
|
"filestore", "bluestore"], "objectstore must be set to 'filestore' or 'bluestore'" # noqa E501
|
2018-04-24 00:06:22 +08:00
|
|
|
|
|
|
|
|
2018-04-27 04:47:33 +08:00
|
|
|
def validate_ceph_stable_release(value):
|
2018-10-11 23:59:31 +08:00
|
|
|
assert value in CEPH_RELEASES, "ceph_stable_release must be set to one of the following: %s" % ", ".join( # noqa E501
|
|
|
|
CEPH_RELEASES)
|
2018-04-27 04:47:33 +08:00
|
|
|
|
|
|
|
|
2018-05-01 00:04:42 +08:00
|
|
|
def validate_rados_options(value):
|
|
|
|
"""
|
|
|
|
Either radosgw_interface, radosgw_address or radosgw_address_block must
|
|
|
|
be defined.
|
|
|
|
"""
|
2018-11-29 03:53:10 +08:00
|
|
|
radosgw_address_given = notario_store["radosgw_address"] != "0.0.0.0"
|
2018-05-01 00:04:42 +08:00
|
|
|
radosgw_address_block_given = notario_store["radosgw_address_block"] != "subnet"
|
|
|
|
radosgw_interface_given = notario_store["radosgw_interface"] != "interface"
|
|
|
|
|
2018-10-11 23:59:31 +08:00
|
|
|
msg = "Either radosgw_address, radosgw_address_block or radosgw_interface must be provided" # noqa E501
|
2018-05-01 00:04:42 +08:00
|
|
|
|
2018-10-11 23:59:31 +08:00
|
|
|
assert any([radosgw_address_given, radosgw_address_block_given,
|
|
|
|
radosgw_interface_given]), msg
|
2018-05-01 00:04:42 +08:00
|
|
|
|
|
|
|
|
2018-04-12 04:03:53 +08:00
|
|
|
install_options = (
|
|
|
|
("ceph_origin", ceph_origin_choices),
|
2018-05-03 05:11:51 +08:00
|
|
|
("containerized_deployment", types.boolean),
|
2018-04-12 04:03:53 +08:00
|
|
|
('osd_objectstore', osd_objectstore_choices),
|
|
|
|
)
|
|
|
|
|
|
|
|
ceph_origin_repository = ("ceph_repository", ceph_repository_choices)
|
|
|
|
|
|
|
|
ceph_repository_community = (
|
|
|
|
("ceph_mirror", types.string),
|
|
|
|
("ceph_stable_key", types.string),
|
2018-04-27 04:47:33 +08:00
|
|
|
("ceph_stable_release", validate_ceph_stable_release),
|
2018-04-12 04:03:53 +08:00
|
|
|
("ceph_stable_repo", types.string),
|
|
|
|
)
|
|
|
|
|
|
|
|
ceph_repository_rhcs = (
|
|
|
|
("ceph_repository_type", ceph_repository_type_choices),
|
|
|
|
("ceph_rhcs_version", chainable.AnyIn(types.string, types.integer)),
|
|
|
|
)
|
|
|
|
|
|
|
|
ceph_repository_dev = (
|
|
|
|
("ceph_dev_branch", types.string),
|
|
|
|
("ceph_dev_sha1", types.string),
|
2018-03-23 21:57:28 +08:00
|
|
|
)
|
2018-04-19 02:29:25 +08:00
|
|
|
|
2019-01-21 16:08:39 +08:00
|
|
|
ceph_repository_custom = ("ceph_custom_repo", types.string)
|
|
|
|
|
2019-03-23 03:03:15 +08:00
|
|
|
ceph_repository_uca = (
|
|
|
|
("ceph_stable_repo_uca", types.string),
|
|
|
|
("ceph_stable_openstack_release_uca", types.string),
|
|
|
|
("ceph_stable_release_uca", types.string),
|
|
|
|
)
|
|
|
|
|
2018-04-19 02:29:25 +08:00
|
|
|
monitor_options = (
|
|
|
|
("cluster_network", types.string),
|
|
|
|
("fsid", types.string),
|
|
|
|
("monitor_address", validate_monitor_options),
|
|
|
|
("monitor_address_block", validate_monitor_options),
|
|
|
|
("monitor_interface", validate_monitor_options),
|
2018-04-24 00:06:22 +08:00
|
|
|
("public_network", types.string),
|
|
|
|
)
|
|
|
|
|
2018-05-01 00:04:42 +08:00
|
|
|
rados_options = (
|
|
|
|
("radosgw_address", validate_rados_options),
|
|
|
|
("radosgw_address_block", validate_rados_options),
|
|
|
|
("radosgw_interface", validate_rados_options),
|
|
|
|
)
|
|
|
|
|
2018-04-24 00:06:22 +08:00
|
|
|
osd_options = (
|
2019-04-04 04:22:47 +08:00
|
|
|
(optional("dmcrypt"), validate_dmcrypt_bool_value),
|
2018-10-12 00:01:10 +08:00
|
|
|
(optional("osd_auto_discovery"), types.boolean),
|
2018-04-24 00:06:22 +08:00
|
|
|
)
|
|
|
|
|
2018-08-04 00:15:58 +08:00
|
|
|
lvm_batch_scenario = ("devices", iterables.AllItems(types.string))
|
|
|
|
|
2018-05-21 20:09:00 +08:00
|
|
|
lvm_filestore_scenario = ("lvm_volumes", iterables.AllItems((
|
|
|
|
(optional('crush_device_class'), types.string),
|
|
|
|
('data', types.string),
|
|
|
|
(optional('data_vg'), types.string),
|
|
|
|
('journal', types.string),
|
|
|
|
(optional('journal_vg'), types.string),
|
|
|
|
)))
|
|
|
|
|
|
|
|
lvm_bluestore_scenario = ("lvm_volumes", iterables.AllItems((
|
2018-04-24 00:06:22 +08:00
|
|
|
(optional('crush_device_class'), types.string),
|
|
|
|
('data', types.string),
|
|
|
|
(optional('data_vg'), types.string),
|
|
|
|
(optional('db'), types.string),
|
|
|
|
(optional('db_vg'), types.string),
|
|
|
|
(optional('wal'), types.string),
|
|
|
|
(optional('wal_vg'), types.string),
|
|
|
|
)))
|