1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# Copyright: (c) 2017, Red Hat, Inc.
5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7ANSIBLE_METADATA = {'metadata_version': '1.1',
8                    'status': ['preview'],
9                    'supported_by': 'core'}
10
11DOCUMENTATION = r'''
12module: win_domain
13short_description: Ensures the existence of a Windows domain
14version_added: 2.3
15description:
16- Ensure that the domain named by C(dns_domain_name) exists and is reachable.
17- If the domain is not reachable, the domain is created in a new forest on the target Windows Server 2012R2+ host.
18- This module may require subsequent use of the M(win_reboot) action if changes are made.
19options:
20  dns_domain_name:
21    description:
22    - The DNS name of the domain which should exist and be reachable or reside on the target Windows host.
23    type: str
24    required: yes
25  domain_netbios_name:
26    description:
27    - The NetBIOS name for the root domain in the new forest.
28    - For NetBIOS names to be valid for use with this parameter they must be single label names of 15 characters or less, if not it will fail.
29    - If this parameter is not set, then the default is automatically computed from the value of the I(domain_name) parameter.
30    type: str
31    version_added: '2.6'
32  safe_mode_password:
33    description:
34    - Safe mode password for the domain controller.
35    type: str
36    required: yes
37  database_path:
38    description:
39    - The path to a directory on a fixed disk of the Windows host where the
40      domain database will be created.
41    - If not set then the default path is C(%SYSTEMROOT%\NTDS).
42    type: path
43    version_added: '2.5'
44  sysvol_path:
45    description:
46    - The path to a directory on a fixed disk of the Windows host where the
47      Sysvol file will be created.
48    - If not set then the default path is C(%SYSTEMROOT%\SYSVOL).
49    type: path
50    version_added: '2.5'
51  create_dns_delegation:
52    description:
53    - Whether to create a DNS delegation that references the new DNS server that you install along with the domain controller.
54    - Valid for Active Directory-integrated DNS only.
55    - The default is computed automatically based on the environment.
56    type: bool
57    version_added: '2.8'
58  domain_mode:
59    description:
60    - Specifies the domain functional level of the first domain in the creation of a new forest.
61    - The domain functional level cannot be lower than the forest functional level, but it can be higher.
62    - The default is automatically computed and set.
63    type: str
64    choices: [ Win2003, Win2008, Win2008R2, Win2012, Win2012R2, WinThreshold ]
65    version_added: '2.8'
66  forest_mode:
67    description:
68    - Specifies the forest functional level for the new forest.
69    - The default forest functional level in Windows Server is typically the same as the version you are running.
70#    - Beware that the default forest functional level in Windows Server 2008 R2 when you create a new forest is C(Win2003).
71    type: str
72    choices: [ Win2003, Win2008, Win2008R2, Win2012, Win2012R2, WinThreshold ]
73    version_added: '2.8'
74seealso:
75- module: win_domain_controller
76- module: win_domain_computer
77- module: win_domain_group
78- module: win_domain_membership
79- module: win_domain_user
80author:
81- Matt Davis (@nitzmahone)
82'''
83
84RETURN = r'''
85reboot_required:
86    description: True if changes were made that require a reboot.
87    returned: always
88    type: bool
89    sample: true
90'''
91
92EXAMPLES = r'''
93- name: Create new domain in a new forest on the target host
94  win_domain:
95    dns_domain_name: ansible.vagrant
96    safe_mode_password: password123!
97
98- name: Create new Windows domain in a new forest with specific parameters
99  win_domain:
100    create_dns_delegation: no
101    database_path: C:\Windows\NTDS
102    dns_domain_name: ansible.vagrant
103    domain_mode: Win2012R2
104    domain_netbios_name: ANSIBLE
105    forest_mode: Win2012R2
106    safe_mode_password: password123!
107    sysvol_path: C:\Windows\SYSVOL
108  register: domain_install
109'''
110