Blame roles/ipaclient/library/ipaclient_set_hostname.py

Packit 8cb997
#!/usr/bin/python
Packit 8cb997
# -*- coding: utf-8 -*-
Packit 8cb997
Packit 8cb997
# Authors:
Packit 8cb997
#   Thomas Woerner <twoerner@redhat.com>
Packit 8cb997
#
Packit 8cb997
# Based on ipa-client-install code
Packit 8cb997
#
Packit 8cb997
# Copyright (C) 2018  Red Hat
Packit 8cb997
# see file 'COPYING' for use and warranty information
Packit 8cb997
#
Packit 8cb997
# This program is free software; you can redistribute it and/or modify
Packit 8cb997
# it under the terms of the GNU General Public License as published by
Packit 8cb997
# the Free Software Foundation, either version 3 of the License, or
Packit 8cb997
# (at your option) any later version.
Packit 8cb997
#
Packit 8cb997
# This program is distributed in the hope that it will be useful,
Packit 8cb997
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8cb997
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8cb997
# GNU General Public License for more details.
Packit 8cb997
#
Packit 8cb997
# You should have received a copy of the GNU General Public License
Packit 8cb997
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 8cb997
Packit 8cb997
ANSIBLE_METADATA = {
Packit 8cb997
    'metadata_version': '1.0',
Packit 8cb997
    'supported_by': 'community',
Packit 8cb997
    'status': ['preview'],
Packit 8cb997
}
Packit 8cb997
Packit 8cb997
DOCUMENTATION = '''
Packit 8cb997
---
Packit 8cb997
module: ipaclient_set_hostname
Packit 8cb997
short description: Backup and set hostname
Packit 8cb997
description:
Packit 8cb997
  Backup and set hostname
Packit 8cb997
options:
Packit 8cb997
  hostname:
Packit 8cb997
    description: Fully qualified name of this host
Packit 8cb997
    required: no
Packit 8cb997
author:
Packit 8cb997
    - Thomas Woerner
Packit 8cb997
'''
Packit 8cb997
Packit 8cb997
EXAMPLES = '''
Packit 8cb997
# Backup and set hostname
Packit 8cb997
- name: Backup and set hostname
Packit 8cb997
  ipaclient_set_hostname:
Packit 8cb997
    hostname: client1.example.com
Packit 8cb997
'''
Packit 8cb997
Packit 8cb997
RETURN = '''
Packit 8cb997
'''
Packit 8cb997
Packit 8cb997
from ansible.module_utils.basic import AnsibleModule
Packit 8cb997
from ansible.module_utils.ansible_ipa_client import (
Packit 8cb997
    sysrestore, paths, tasks
Packit 8cb997
)
Packit 8cb997
Packit 8cb997
Packit 8cb997
def main():
Packit 8cb997
    module = AnsibleModule(
Packit 8cb997
        argument_spec=dict(
Packit 8cb997
            hostname=dict(required=True),
Packit 8cb997
        ),
Packit 8cb997
        supports_check_mode=True,
Packit 8cb997
    )
Packit 8cb997
Packit 8cb997
    module._ansible_debug = True
Packit 8cb997
    hostname = module.params.get('hostname')
Packit 8cb997
Packit 8cb997
    fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
Packit 8cb997
    statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE)
Packit 8cb997
Packit 8cb997
    tasks.backup_hostname(fstore, statestore)
Packit 8cb997
    tasks.set_hostname(hostname)
Packit 8cb997
Packit 8cb997
    module.exit_json(changed=True)
Packit 8cb997
Packit 8cb997
Packit 8cb997
if __name__ == '__main__':
Packit 8cb997
    main()