The following exercises are going to involve creating playbooks that will configure our new Windows systems, and install Active Directory. Later on, we’ll tie them all together using a workflow.
To start, we’ll create a playbook that waits for the VMs to be available. Create a new directory in your code repository called playbooks
, and add a new file called wait-for-connectivity.yaml
with the following contents:
---
- name: Wait for systems to be available
hosts:
- all
gather_facts: false
tasks:
- name: Wait for connectivity
ansible.builtin.wait_for_connection:
timeout: 600
This will ensure the VMs can be contacted before attempting the next steps.
Create a new file in the playbooks/
directory called set-base-configs.yaml
, and add the following contents:
---
- name: Set some basic system configs
hosts:
- all
tasks:
- name: Set the system hostname
ansible.windows.win_hostname:
name: "{{ inventory_hostname }}"
notify:
- reboot
handlers:
- name: Reboot system
ansible.windows.win_reboot:
listen:
- reboot
This will set the hostname of the systems, and since they’re Windows, they’ll reboot if a change is made.
Create another file in the playbooks/
directory named create-ad-forest.yaml
, and add the following contents:
---
- name: Create Active Directory forest
hosts:
- all
tasks:
- name: Create AD forest/domain
microsoft.ad.domain:
dns_domain_name: "{{ active_directory.dns_domain_name }}"
safe_mode_password: "{{ ansible_password }}"
domain_netbios_name: "{{ active_directory.domain_netbios_name | default(omit) }}"
reboot: true
A few quick notes about this playbook:
Active Directory Infrastructure
inventory and review the Variables
field.
With these playbooks, we’ll have created and configured an Active Directory forest on a single system. In the next exercise, we’ll add our secondary domain controller.
Navigation
Previous Exercise | Next Exercise |