Skip to content

Commit

Permalink
cephadm-bootstrap: add missing options to module
Browse files Browse the repository at this point in the history
All existing 'cephadm bootstrap' options were not available
in the cephadm-boostrap module. Added xtra_opt_cli parameter
to list additional parameters

Added shebang and coding information to all modules as advised by(1)

(1) https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_documenting.html#python-shebang-utf-8-coding

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2246266

Signed-off-by: Teoman ONAY <[email protected]>
  • Loading branch information
asm0deuz committed Feb 9, 2024
1 parent a51f517 commit 0622302
Showing 1 changed file with 119 additions and 91 deletions.
210 changes: 119 additions & 91 deletions library/cephadm_bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright Red Hat
# SPDX-License-Identifier: Apache-2.0
#
Expand Down Expand Up @@ -123,6 +126,7 @@
required: false
author:
- Dimitri Savineau <[email protected]>
- Teoman ONAY <[email protected]>
'''

EXAMPLES = '''
Expand All @@ -149,59 +153,90 @@
RETURN = '''# '''


def main() -> None:
def run_module() -> None:

backward_compat = dict(
dashboard=dict(type='bool', required=False, remove_in_version='4.0.0'),
firewalld=dict(type='bool', required=False, remove_in_version='4.0.0'),
monitoring=dict(type='bool', required=False, remove_in_version='4.0.0'),
pull=dict(type='bool', required=False, remove_in_version='4.0.0'),
)

cephadm_params = dict(
docker=dict(type='bool', required=False, default=False),
image=dict(type='str', required=False),
)

cephadm_bootstrap_params = dict(
allow_fqdn_hostname=dict(type='bool', required=False, default=False),
allow_mismatched_release=dict(type='bool', required=False),
allow_overwrite=dict(type='bool', required=False, default=False),
apply_spec=dict(type='str', required=False),
cluster_network=dict(type='str', required=False),
config=dict(type='str', required=False),
dashboard_crt=dict(type='str', required=False),
dashboard_key=dict(type='str', required=False),
dashboard_password_noupdate=dict(type='bool', required=False),
fsid=dict(type='str', required=False),
initial_dashboard_password=dict(type='str', required=False, no_log=True), # noqa: E501
initial_dashboard_user=dict(type='str', required=False),
log_to_file=dict(type='bool', required=False),
mgr_id=dict(type='str', required=False),
mon_addrv=dict(type='str', required=False),
mon_id=dict(type='str', required=False),
mon_ip=dict(type='str', required=False),
no_cleanup_on_failure=dict(type='bool', required=False),
no_minimize_config=dict(type='bool', required=False),
orphan_initial_daemons=dict(type='bool', required=False),
output_config=dict(type='str', required=False),
output_dir=dict(type='str', required=False),
output_keyring=dict(type='str', required=False),
output_pub_ssh_key=dict(type='str', required=False),
registry_json=dict(type='str', required=False),
registry_password=dict(type='str', required=False, no_log=True),
registry_url=dict(type='str', required=False),
registry_username=dict(type='str', required=False),
shared_ceph_folder=dict(type='str', required=False),
single_host_defaults=dict(type='bool', required=False),
skip_admin_label=dict(type='bool', required=False),
skip_dashboard=dict(type='bool', required=False, default=False),
skip_firewalld=dict(type='bool', required=False, default=False),
skip_monitoring_stack=dict(type='bool', required=False, default=False),
skip_mon_network=dict(type='bool', required=False),
skip_ping_check=dict(type='bool', required=False),
skip_prepare_host=dict(type='bool', required=False),
skip_pull=dict(type='bool', required=False),
skip_ssh=dict(type='bool', required=False),
ssh_config=dict(type='str', required=False),
ssh_private_key=dict(type='str', required=False),
ssh_public_key=dict(type='str', required=False),
ssh_signed_cert=dict(type='str', required=False),
ssh_user=dict(type='str', required=False),
ssl_dashboard_port=dict(type='str', required=False),
with_centralized_logging=dict(type='bool', required=False),
)

module = AnsibleModule(
argument_spec=dict(
mon_ip=dict(type='str', required=True),
image=dict(type='str', required=False),
docker=dict(type='bool', required=False, default=False),
fsid=dict(type='str', required=False),
pull=dict(type='bool', required=False, default=True),
dashboard=dict(type='bool', required=False, default=True),
dashboard_user=dict(type='str', required=False),
dashboard_password=dict(type='str', required=False, no_log=True),
monitoring=dict(type='bool', required=False, default=True),
firewalld=dict(type='bool', required=False, default=True),
allow_overwrite=dict(type='bool', required=False, default=False),
registry_url=dict(type='str', require=False),
registry_username=dict(type='str', require=False),
registry_password=dict(type='str', require=False, no_log=True),
registry_json=dict(type='path', require=False),
ssh_user=dict(type='str', required=False),
ssh_config=dict(type='str', required=False),
allow_fqdn_hostname=dict(type='bool', required=False, default=False),
cluster_network=dict(type='str', required=False),
),
argument_spec={**cephadm_params,
**cephadm_bootstrap_params,
**backward_compat},
supports_check_mode=True,
mutually_exclusive=[
('registry_json', 'registry_url'),
('registry_json', 'registry_username'),
('registry_json', 'registry_password'),
('mon_addrv', 'mon_ip'),
],
required_together=[
('registry_url', 'registry_username', 'registry_password')
('registry_url', 'registry_username', 'registry_password'),
('initial_dashboard_user', 'initial_dashboard_password'),
],
required_one_of=[('mon_ip', 'mon_addrv'),
],
)

mon_ip = module.params.get('mon_ip')
docker = module.params.get('docker')
image = module.params.get('image')
fsid = module.params.get('fsid')
pull = module.params.get('pull')
dashboard = module.params.get('dashboard')
dashboard_user = module.params.get('dashboard_user')
dashboard_password = module.params.get('dashboard_password')
monitoring = module.params.get('monitoring')
firewalld = module.params.get('firewalld')
allow_overwrite = module.params.get('allow_overwrite')
registry_url = module.params.get('registry_url')
registry_username = module.params.get('registry_username')
registry_password = module.params.get('registry_password')
registry_json = module.params.get('registry_json')
ssh_user = module.params.get('ssh_user')
ssh_config = module.params.get('ssh_config')
allow_fqdn_hostname = module.params.get('allow_fqdn_hostname')
cluster_network = module.params.get('cluster_network')

startd = datetime.datetime.now()

Expand All @@ -213,7 +248,7 @@ def main() -> None:

if fsid:
if os.path.exists(os.path.join(data_dir, fsid)):
out = 'A cluster with fsid {} is already deployed.'.format(fsid)
out = f"A cluster with fsid {fsid} is already deployed."
exit_module(
rc=0,
startd=startd,
Expand All @@ -223,6 +258,12 @@ def main() -> None:
changed=False
)

def extend_append(key: str, parameters: dict) -> None:
if parameters.get(key) == 'bool':
cmd.append("--" + k.replace('_', '-'))
else:
cmd.extend(["--" + k.replace('_', '-'), module.params.get(k)])

for f in [ceph_conf,
ceph_keyring,
ceph_pubkey]:
Expand All @@ -238,56 +279,39 @@ def main() -> None:
changed=False
)

if docker:
cmd.append('--docker')

if image:
cmd.extend(['--image', image])

cmd.extend(['bootstrap', '--mon-ip', mon_ip])

if fsid:
cmd.extend(['--fsid', fsid])

if not pull:
cmd.append('--skip-pull')

if dashboard:
if dashboard_user:
cmd.extend(['--initial-dashboard-user', dashboard_user])
if dashboard_password:
cmd.extend(['--initial-dashboard-password', dashboard_password])
else:
cmd.append('--skip-dashboard')

if not monitoring:
cmd.append('--skip-monitoring-stack')

if not firewalld:
cmd.append('--skip-firewalld')

if allow_overwrite:
cmd.append('--allow-overwrite')

if registry_url and registry_username and registry_password:
cmd.extend(['--registry-url', registry_url,
'--registry-username', registry_username,
'--registry-password', registry_password])

if registry_json:
cmd.extend(['--registry-json', registry_json])

if ssh_user:
cmd.extend(['--ssh-user', ssh_user])

if ssh_config:
cmd.extend(['--ssh-config', ssh_config])

if allow_fqdn_hostname:
cmd.append('--allow-fqdn-hostname')

if cluster_network:
cmd.extend(['--cluster-network', cluster_network])
for k in cephadm_params:
if module.params.get(k):
extend_append(k, cephadm_params)

cmd.extend(['bootstrap'])

for k in cephadm_bootstrap_params:
if module.params.get(k):
extend_append(k, cephadm_bootstrap_params)

# keep backward compatibility
for k in backward_compat:
result = module.params.get(k)
if result is not None:
if k == 'pull' and not result:
if '--skip-pull' not in cmd:
cmd.append('--skip-pull')
elif k == 'monitoring' and not result:
if '--skip-dashboard' not in cmd:
cmd.append('--skip-dashboard')
elif k == 'firewalld' and not result:
if '--skip-firewalld' not in cmd:
cmd.append('--skip-firewalld')
elif k == 'dashboard' and result:
if '--initial-dashboard-user' not in cmd:
cmd.extend(['--initial-dashboard-user',
module.params.get('initial-dashboard-user'),
'--initial-dashboard-password',
module.params.get('initial-dashboard-password'), # noqa: E501
])
else:
if '--skip-dashboard' not in cmd:
cmd.append('--skip-dashboard')

if module.check_mode:
exit_module(
Expand All @@ -312,5 +336,9 @@ def main() -> None:
)


def main():
run_module()


if __name__ == '__main__':
main()

0 comments on commit 0622302

Please sign in to comment.