Blame roles/ipaserver/library/ipaserver_enable_ipa.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-server-install code
Packit 8cb997
#
Packit 8cb997
# Copyright (C) 2017  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
from __future__ import print_function
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: ipaserver_enable_ipa
Packit 8cb997
short description: Enable IPA
Packit 8cb997
description: Enable IPA
Packit 8cb997
options:
Packit 8cb997
  hostname:
Packit 8cb997
    description: Fully qualified name of this host
Packit 8cb997
    required: yes
Packit 8cb997
  setup_dns:
Packit 8cb997
    description: Configure bind with our zone
Packit 8cb997
    required: no
Packit 8cb997
  setup_ca:
Packit 8cb997
    description: Configure a dogtag CA
Packit 8cb997
    required: no
Packit 8cb997
author:
Packit 8cb997
    - Thomas Woerner
Packit 8cb997
'''
Packit 8cb997
Packit 8cb997
EXAMPLES = '''
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_server import (
Packit Service 0f71a7
    AnsibleModuleLog, setup_logging, options, paths, api, sysrestore, tasks,
Packit 8cb997
    service, bindinstance, redirect_stdout, services
Packit 8cb997
)
Packit 8cb997
Packit 8cb997
Packit 8cb997
def main():
Packit 8cb997
    ansible_module = AnsibleModule(
Packit 8cb997
        argument_spec=dict(
Packit 8cb997
            hostname=dict(required=False),
Packit 8cb997
            setup_dns=dict(required=True, type='bool'),
Packit 8cb997
            setup_ca=dict(required=True, type='bool'),
Packit 8cb997
        ),
Packit 8cb997
    )
Packit 8cb997
Packit 8cb997
    ansible_module._ansible_debug = True
Packit Service 0f71a7
    setup_logging()
Packit 8cb997
    ansible_log = AnsibleModuleLog(ansible_module)
Packit 8cb997
Packit 8cb997
    # set values #############################################################
Packit 8cb997
Packit 8cb997
    options.host_name = ansible_module.params.get('hostname')
Packit 8cb997
    options.setup_dns = ansible_module.params.get('setup_dns')
Packit 8cb997
    options.setup_ca = ansible_module.params.get('setup_ca')
Packit 8cb997
Packit 8cb997
    # Configuration for ipalib, we will bootstrap and finalize later, after
Packit 8cb997
    # we are sure we have the configuration file ready.
Packit 8cb997
    cfg = dict(
Packit 8cb997
        context='installer',
Packit 8cb997
        confdir=paths.ETC_IPA,
Packit 8cb997
        in_server=True,
Packit 8cb997
        # make sure host name specified by user is used instead of default
Packit 8cb997
        host=options.host_name,
Packit 8cb997
    )
Packit 8cb997
    if options.setup_ca:
Packit 8cb997
        # we have an IPA-integrated CA
Packit 8cb997
        cfg['ca_host'] = options.host_name
Packit 8cb997
Packit 8cb997
    api.bootstrap(**cfg)
Packit 8cb997
    api.finalize()
Packit 8cb997
    api.Backend.ldap2.connect()
Packit 8cb997
Packit 8cb997
    # setup ds ######################################################
Packit 8cb997
Packit 8cb997
    fstore = sysrestore.FileStore(paths.SYSRESTORE)
Packit 8cb997
Packit 8cb997
    if hasattr(tasks, "configure_tmpfiles"):
Packit 8cb997
        # Make sure the files we crated in /var/run are recreated at startup
Packit 8cb997
        tasks.configure_tmpfiles()
Packit 8cb997
Packit 8cb997
    if hasattr(service, "enable_services"):
Packit 8cb997
        # Enable configured services and update DNS SRV records
Packit 8cb997
        service.enable_services(options.host_name)
Packit 8cb997
        api.Command.dns_update_system_records()
Packit 8cb997
Packit 8cb997
        if not options.setup_dns:
Packit 8cb997
            # After DNS and AD trust are configured and services are
Packit 8cb997
            # enabled, create a dummy instance to dump DNS configuration.
Packit 8cb997
            bind = bindinstance.BindInstance(fstore)
Packit 8cb997
            bind.create_file_with_system_records()
Packit 8cb997
Packit 8cb997
    with redirect_stdout(ansible_log):
Packit 8cb997
        services.knownservices.ipa.enable()
Packit 8cb997
Packit 8cb997
    ansible_module.exit_json(changed=True)
Packit 8cb997
Packit 8cb997
Packit 8cb997
if __name__ == '__main__':
Packit 8cb997
    main()