2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-08-05 12:28:29 +02:00
|
|
|
# Copyright Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2020-07-31 10:57:57 +02:00
|
|
|
DOCUMENTATION = r'''
|
2020-03-09 10:11:07 +01:00
|
|
|
---
|
|
|
|
module: atomic_host
|
|
|
|
short_description: Manage the atomic host platform
|
|
|
|
description:
|
|
|
|
- Manage the atomic host platform.
|
|
|
|
- Rebooting of Atomic host platform should be done outside this module.
|
|
|
|
author:
|
|
|
|
- Saravanan KR (@krsacme)
|
|
|
|
notes:
|
|
|
|
- Host should be an atomic platform (verified by existence of '/run/ostree-booted' file).
|
|
|
|
requirements:
|
|
|
|
- atomic
|
Add attributes to atomic, memset, one, oneview, packet, proxmox, and xenserver modules (#5958)
Add attributes to atomic, memset, one, oneview, packet, proxmox, and xenserver modules.
2023-02-20 17:27:38 +01:00
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.attributes
|
|
|
|
attributes:
|
|
|
|
check_mode:
|
|
|
|
support: none
|
|
|
|
diff_mode:
|
|
|
|
support: none
|
2020-03-09 10:11:07 +01:00
|
|
|
options:
|
|
|
|
revision:
|
|
|
|
description:
|
2020-07-31 10:57:57 +02:00
|
|
|
- The version number of the atomic host to be deployed.
|
2023-06-20 08:14:02 +02:00
|
|
|
- Providing V(latest) will upgrade to the latest available version.
|
2020-07-31 10:57:57 +02:00
|
|
|
default: 'latest'
|
2020-03-09 10:11:07 +01:00
|
|
|
aliases: [ version ]
|
2020-07-31 10:57:57 +02:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
2020-07-31 10:57:57 +02:00
|
|
|
EXAMPLES = r'''
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Upgrade the atomic host platform to the latest version (atomic host upgrade)
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.atomic_host:
|
2020-03-09 10:11:07 +01:00
|
|
|
revision: latest
|
|
|
|
|
|
|
|
- name: Deploy a specific revision as the atomic host (atomic host deploy 23.130)
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.atomic_host:
|
2020-03-09 10:11:07 +01:00
|
|
|
revision: 23.130
|
|
|
|
'''
|
|
|
|
|
2020-07-31 10:57:57 +02:00
|
|
|
RETURN = r'''
|
2020-03-09 10:11:07 +01:00
|
|
|
msg:
|
|
|
|
description: The command standard output
|
|
|
|
returned: always
|
|
|
|
type: str
|
|
|
|
sample: 'Already on latest'
|
|
|
|
'''
|
|
|
|
import os
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2021-06-26 23:59:11 +02:00
|
|
|
from ansible.module_utils.common.text.converters import to_native
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
def core(module):
|
|
|
|
revision = module.params['revision']
|
2021-04-02 22:06:07 +02:00
|
|
|
atomic_bin = module.get_bin_path('atomic', required=True)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
|
|
|
|
|
|
|
|
if revision == 'latest':
|
2021-04-02 22:06:07 +02:00
|
|
|
args = [atomic_bin, 'host', 'upgrade']
|
2020-03-09 10:11:07 +01:00
|
|
|
else:
|
2021-04-02 22:06:07 +02:00
|
|
|
args = [atomic_bin, 'host', 'deploy', revision]
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
rc, out, err = module.run_command(args, check_rc=False)
|
|
|
|
|
|
|
|
if rc == 77 and revision == 'latest':
|
|
|
|
module.exit_json(msg="Already on latest", changed=False)
|
|
|
|
elif rc != 0:
|
|
|
|
module.fail_json(rc=rc, msg=err)
|
|
|
|
else:
|
|
|
|
module.exit_json(msg=out, changed=True)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
revision=dict(type='str', default='latest', aliases=["version"]),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Verify that the platform is atomic host
|
|
|
|
if not os.path.exists("/run/ostree-booted"):
|
|
|
|
module.fail_json(msg="Module atomic_host is applicable for Atomic Host Platforms only")
|
|
|
|
|
|
|
|
try:
|
|
|
|
core(module)
|
|
|
|
except Exception as e:
|
|
|
|
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|