Blame roles/ipaclient/library/ipaclient_setup_sssd.py

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) 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
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_setup_ssd
Packit 8cb997
short description: Setup sssd for IPA client
Packit 8cb997
description:
Packit 8cb997
  Setup sssd for IPA client
Packit 8cb997
options:
Packit 8cb997
  servers:
Packit 8cb997
    description: Fully qualified name of IPA servers to enroll to
Packit 8cb997
    required: no
Packit 8cb997
  domain:
Packit 8cb997
    description: Primary DNS domain of the IPA deployment
Packit 8cb997
    required: no
Packit 8cb997
  realm:
Packit 8cb997
    description: Kerberos realm name of the IPA deployment
Packit 8cb997
    required: no
Packit 8cb997
  hostname:
Packit 8cb997
    description: Fully qualified name of this host
Packit 8cb997
    required: no
Packit 8cb997
  on_master:
Packit 8cb997
    description: Whether the configuration is done on the master or not
Packit 8cb997
    required: yes
Packit 8cb997
  no_ssh:
Packit 8cb997
    description: Do not configure OpenSSH client
Packit 8cb997
    required: yes
Packit 8cb997
  no_sshd:
Packit 8cb997
    description: Do not configure OpenSSH server
Packit 8cb997
    required: yes
Packit 8cb997
  no_sudo:
Packit 8cb997
    description: Do not configure SSSD as data source for sudo
Packit 8cb997
    required: yes
Packit 8cb997
  all_ip_addresses:
Packit 8cb997
    description:
Packit 8cb997
      All routable IP addresses configured on any interface will be added
Packit 8cb997
      to DNS
Packit 8cb997
    required: yes
Packit 8cb997
  fixed_primary:
Packit 8cb997
    description: Configure sssd to use fixed server as primary IPA server
Packit 8cb997
    required: yes
Packit 8cb997
  permit:
Packit 8cb997
    description: Disable access rules by default, permit all access
Packit 8cb997
    required: yes
Packit 8cb997
  enable_dns_updates:
Packit 8cb997
    description:
Packit 8cb997
      Configures the machine to attempt dns updates when the ip address
Packit 8cb997
      changes
Packit 8cb997
    required: yes
Packit 8cb997
  preserve_sssd:
Packit 8cb997
    description: Preserve old SSSD configuration if possible
Packit 8cb997
    required: yes
Packit 8cb997
  no_krb5_offline_passwords:
Packit 8cb997
    description:
Packit 8cb997
      Configure SSSD not to store user password when the server is offline
Packit 8cb997
    required: yes
Packit 8cb997
author:
Packit 8cb997
    - Thomas Woerner
Packit 8cb997
'''
Packit 8cb997
Packit 8cb997
EXAMPLES = '''
Packit 8cb997
- name: Configure SSSD
Packit 8cb997
  ipaclient_setup_sssd:
Packit 8cb997
    servers: ["server1.example.com","server2.example.com"]
Packit 8cb997
    domain: example.com
Packit 8cb997
    realm: EXAMPLE.COM
Packit 8cb997
    hostname: client1.example.com
Packit 8cb997
    no_krb5_offline_passwords: yes
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 Service 0f71a7
    setup_logging, options, sysrestore, paths, configure_sssd_conf, logger
Packit 8cb997
)
Packit 8cb997
Packit 8cb997
Packit 8cb997
def main():
Packit 8cb997
    module = AnsibleModule(
Packit 8cb997
        argument_spec=dict(
Packit 8cb997
            servers=dict(required=True, type='list'),
Packit 8cb997
            domain=dict(required=True),
Packit 8cb997
            realm=dict(required=True),
Packit 8cb997
            hostname=dict(required=True),
Packit 8cb997
            on_master=dict(required=False, type='bool'),
Packit 8cb997
            no_ssh=dict(required=False, type='bool'),
Packit 8cb997
            no_sshd=dict(required=False, type='bool'),
Packit 8cb997
            no_sudo=dict(required=False, type='bool'),
Packit 8cb997
            all_ip_addresses=dict(required=False, type='bool'),
Packit 8cb997
Packit 8cb997
            fixed_primary=dict(required=False, type='bool'),
Packit 8cb997
            permit=dict(required=False, type='bool'),
Packit 8cb997
            enable_dns_updates=dict(required=False, type='bool'),
Packit 8cb997
            preserve_sssd=dict(required=False, type='bool'),
Packit 8cb997
            no_krb5_offline_passwords=dict(required=False, type='bool'),
Packit 8cb997
        ),
Packit 8cb997
        supports_check_mode=True,
Packit 8cb997
    )
Packit 8cb997
    # ansible_log = AnsibleModuleLog(module, logger)
Packit 8cb997
    # options.set_logger(ansible_log)
Packit 8cb997
Packit 8cb997
    module._ansible_debug = True
Packit Service 0f71a7
    setup_logging()
Packit Service 0f71a7
Packit 8cb997
    cli_server = module.params.get('servers')
Packit 8cb997
    cli_domain = module.params.get('domain')
Packit 8cb997
    cli_realm = module.params.get('realm')
Packit 8cb997
    hostname = module.params.get('hostname')
Packit 8cb997
    options.on_master = module.params.get('on_master')
Packit 8cb997
Packit 8cb997
    options.no_ssh = module.params.get('no_ssh')
Packit 8cb997
    options.conf_ssh = not options.no_ssh
Packit 8cb997
    options.no_sshd = module.params.get('no_sshd')
Packit 8cb997
    options.conf_sshd = not options.no_sshd
Packit 8cb997
    options.no_sudo = module.params.get('no_sudo')
Packit 8cb997
    options.conf_sudo = not options.no_sudo
Packit 8cb997
    options.all_ip_addresses = module.params.get('all_ip_addresses')
Packit 8cb997
Packit 8cb997
    options.primary = module.params.get('fixed_primary')
Packit 8cb997
    options.permit = module.params.get('permit')
Packit 8cb997
    options.dns_updates = module.params.get('enable_dns_updates')
Packit 8cb997
    options.preserve_sssd = module.params.get('preserve_sssd')
Packit 8cb997
Packit 8cb997
    options.no_krb5_offline_passwords = module.params.get(
Packit 8cb997
        'no_krb5_offline_passwords')
Packit 8cb997
    options.krb5_offline_passwords = not options.no_krb5_offline_passwords
Packit 8cb997
Packit 8cb997
    fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
Packit 8cb997
    client_domain = hostname[hostname.find(".")+1:]
Packit 8cb997
Packit 8cb997
    if configure_sssd_conf(fstore, cli_realm, cli_domain, cli_server,
Packit 8cb997
                           options, client_domain, hostname):
Packit 8cb997
        module.fail_json("configure_sssd_conf failed")
Packit 8cb997
    logger.info("Configured /etc/sssd/sssd.conf")
Packit 8cb997
Packit 8cb997
    module.exit_json(changed=True)
Packit 8cb997
Packit 8cb997
Packit 8cb997
if __name__ == '__main__':
Packit 8cb997
    main()