Blame roles/ipaserver/library/ipaserver_master_password.py

Packit Service 0a38ef
# -*- coding: utf-8 -*-
Packit Service 0a38ef
Packit Service 0a38ef
# Authors:
Packit Service 0a38ef
#   Thomas Woerner <twoerner@redhat.com>
Packit Service 0a38ef
#
Packit Service 0a38ef
# Based on ipa-server-install code
Packit Service 0a38ef
#
Packit Service 0a38ef
# Copyright (C) 2017  Red Hat
Packit Service 0a38ef
# see file 'COPYING' for use and warranty information
Packit Service 0a38ef
#
Packit Service 0a38ef
# This program is free software; you can redistribute it and/or modify
Packit Service 0a38ef
# it under the terms of the GNU General Public License as published by
Packit Service 0a38ef
# the Free Software Foundation, either version 3 of the License, or
Packit Service 0a38ef
# (at your option) any later version.
Packit Service 0a38ef
#
Packit Service 0a38ef
# This program is distributed in the hope that it will be useful,
Packit Service 0a38ef
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 0a38ef
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 0a38ef
# GNU General Public License for more details.
Packit Service 0a38ef
#
Packit Service 0a38ef
# You should have received a copy of the GNU General Public License
Packit Service 0a38ef
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service 0a38ef
Packit Service 0a38ef
ANSIBLE_METADATA = {
Packit Service 0a38ef
    'metadata_version': '1.0',
Packit Service 0a38ef
    'supported_by': 'community',
Packit Service 0a38ef
    'status': ['preview'],
Packit Service 0a38ef
}
Packit Service 0a38ef
Packit Service 0a38ef
DOCUMENTATION = '''
Packit Service 0a38ef
---
Packit Service 0a38ef
module: ipaserver_master_password
Packit Service 0a38ef
short description: Generate kerberos master password if not given
Packit Service 0a38ef
description:
Packit Service 0a38ef
  Generate kerberos master password if not given
Packit Service 0a38ef
options:
Packit Service 0a38ef
  dm_password:
Packit Service 0a38ef
    description: Directory Manager password
Packit Service 0a38ef
    required: no
Packit Service 0a38ef
  master_password:
Packit Service 0a38ef
    description: kerberos master password (normally autogenerated)
Packit Service 0a38ef
    required: yes
Packit Service 0a38ef
author:
Packit Service 0a38ef
    - Thomas Woerner
Packit Service 0a38ef
'''
Packit Service 0a38ef
Packit Service 0a38ef
EXAMPLES = '''
Packit Service 0a38ef
'''
Packit Service 0a38ef
Packit Service 0a38ef
RETURN = '''
Packit Service 0a38ef
password:
Packit Service 0a38ef
  description: The master password
Packit Service 0a38ef
  returned: always
Packit Service 0a38ef
'''
Packit Service 0a38ef
Packit Service 0a38ef
import os
Packit Service 0a38ef
Packit Service 0a38ef
from ansible.module_utils.basic import AnsibleModule
Packit Service 0a38ef
from ansible.module_utils.ansible_ipa_server import (
Packit Service 0a38ef
    setup_logging, options, paths, read_cache, ipa_generate_password
Packit Service 0a38ef
)
Packit Service 0a38ef
Packit Service 0a38ef
Packit Service 0a38ef
def main():
Packit Service 0a38ef
    module = AnsibleModule(
Packit Service 0a38ef
        argument_spec=dict(
Packit Service 0a38ef
            # basic
Packit Service 0a38ef
            dm_password=dict(required=True, no_log=True),
Packit Service 0a38ef
            master_password=dict(required=False, no_log=True),
Packit Service 0a38ef
        ),
Packit Service 0a38ef
        supports_check_mode=True,
Packit Service 0a38ef
    )
Packit Service 0a38ef
Packit Service 0a38ef
    module._ansible_debug = True
Packit Service 0a38ef
    setup_logging()
Packit Service 0a38ef
Packit Service 0a38ef
    options.dm_password = module.params.get('dm_password')
Packit Service 0a38ef
    options.master_password = module.params.get('master_password')
Packit Service 0a38ef
Packit Service 0a38ef
    # This will override any settings passed in on the cmdline
Packit Service 0a38ef
    if os.path.isfile(paths.ROOT_IPA_CACHE):
Packit Service 0a38ef
        # dm_password check removed, checked already
Packit Service 0a38ef
        try:
Packit Service 0a38ef
            cache_vars = read_cache(options.dm_password)
Packit Service 0a38ef
            options.__dict__.update(cache_vars)
Packit Service 0a38ef
        except Exception as e:
Packit Service 0a38ef
            module.fail_json(msg="Cannot process the cache file: %s" % str(e))
Packit Service 0a38ef
Packit Service 0a38ef
    if not options.master_password:
Packit Service 0a38ef
        options.master_password = ipa_generate_password()
Packit Service 0a38ef
Packit Service 0a38ef
    module.exit_json(changed=True,
Packit Service 0a38ef
                     password=options.master_password)
Packit Service 0a38ef
Packit Service 0a38ef
Packit Service 0a38ef
if __name__ == '__main__':
Packit Service 0a38ef
    main()