Blame roles/ipaclient/library/ipaclient_setup_sssd.py

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