mirror of
https://git.ecdf.ed.ac.uk/win_automation/windows-ansible.git
synced 2026-10-26 16:37:21 +00:00
143 lines
4.3 KiB
YAML
143 lines
4.3 KiB
YAML
---
|
|
- name: Promote DC01
|
|
tags: promote_dc01
|
|
block:
|
|
- name: Promote DC01 to domain controller
|
|
win_domain:
|
|
dns_domain_name: "{{ win_project }}.loc"
|
|
safe_mode_password: "{{ safemode_password }}"
|
|
domain_netbios_name: "{{ win_project|upper }}"
|
|
register: dc01_promotion
|
|
|
|
- name: Setting DNS Servers (Primary DC)
|
|
vars:
|
|
dc02_dns: "{{ os_project }}-{{ win_project }}-dc02"
|
|
win_dns_client:
|
|
adapter_names: "*"
|
|
dns_servers:
|
|
- "127.0.0.1"
|
|
- "{{ hostvars[dc02_dns].ansible_host }}"
|
|
|
|
- name: Copy ADMX/ADML files
|
|
tags: copy_admx
|
|
block:
|
|
- name: Copy ADMX and ADML files to DCs
|
|
win_copy:
|
|
src: policy_templates/PolicyDefinitions
|
|
dest: "C:\\Windows\\SYSVOL\\sysvol\\{{ win_project }}.loc\\policies\\"
|
|
force: true
|
|
|
|
- name: Rebooting DC01 post promotion to domain controller
|
|
win_reboot:
|
|
reboot_timeout_sec: 1200
|
|
when: dc01_promotion.reboot_required | default(false) == true
|
|
when: inventory_hostname in groups['meta-name_dc01']
|
|
|
|
- name: Promote DC02
|
|
tags: promote_dc02
|
|
block:
|
|
- name: Setting DNS Servers (Secondary DC)
|
|
vars:
|
|
dc01_dns: "{{ os_project }}-{{ win_project }}-dc01"
|
|
win_dns_client:
|
|
adapter_names: "*"
|
|
dns_servers:
|
|
- "{{ hostvars[dc01_dns].ansible_host }}"
|
|
- "127.0.0.1"
|
|
|
|
- name: wait for 30 seconds for DNS
|
|
pause:
|
|
seconds: 30
|
|
|
|
- name: flush DNS cache
|
|
win_shell: ipconfig /flushdns
|
|
|
|
- name: Promote DC02 to domain controller
|
|
win_domain_controller:
|
|
dns_domain_name: "{{ win_project }}.loc"
|
|
domain_admin_user: "Administrator@{{ win_project }}.loc"
|
|
domain_admin_password: "{{ ansible_password }}"
|
|
safe_mode_password: "{{ safemode_password }}"
|
|
state: domain_controller
|
|
register: dc02_promotion
|
|
|
|
rescue:
|
|
- name: Wait 2 minutes before trying to promote again
|
|
pause:
|
|
minutes: 2
|
|
|
|
- name: Promote DC02 to domain controller
|
|
win_domain_controller:
|
|
dns_domain_name: "{{ win_project }}.loc"
|
|
domain_admin_user: "Administrator@{{ win_project }}.loc"
|
|
domain_admin_password: "{{ ansible_password }}"
|
|
safe_mode_password: "{{ safemode_password }}"
|
|
state: domain_controller
|
|
register: dc02_promotion
|
|
|
|
always:
|
|
- name: Setting DNS Servers (Secondary DC)
|
|
vars:
|
|
dc01_dns: "{{ os_project }}-{{ win_project }}-dc01"
|
|
win_dns_client:
|
|
adapter_names: "*"
|
|
dns_servers:
|
|
- "127.0.0.1"
|
|
- "{{ hostvars[dc01_dns].ansible_host }}"
|
|
|
|
- name: Rebooting DC02 post promotion to domain controller
|
|
win_reboot:
|
|
reboot_timeout_sec: 1200
|
|
when: dc02_promotion.reboot_required | default(false) == true
|
|
when: inventory_hostname in groups['meta-name_dc02']
|
|
|
|
- name: Group policy script
|
|
tags: gpo_script
|
|
block:
|
|
- name: Copy Group Policy script to DC01
|
|
win_copy:
|
|
src: "{{ group_policy_script }}"
|
|
dest: "C:\\eidf"
|
|
force: true
|
|
tags: copy_gpo_script
|
|
|
|
- name: Apply group policy
|
|
win_shell: powershell C:\eidf\{{ group_policy_script }}
|
|
tags: apply_gpo_script
|
|
when: inventory_hostname in groups['meta-name_dc01']
|
|
|
|
- name: Server Hardening script
|
|
tags: hardening_script
|
|
block:
|
|
- name: Copy Server Hardening script to DC01
|
|
win_copy:
|
|
src: "{{ server_hardening_script }}"
|
|
dest: "C:\\eidf"
|
|
force: true
|
|
tags: copy_hardening_script
|
|
|
|
- name: Apply server hardening
|
|
win_shell: powershell C:\eidf\{{ server_hardening_script }}
|
|
tags: apply_hardening_scripts
|
|
when: inventory_hostname in groups['meta-name_dc01']
|
|
|
|
- name: Squid Proxy GPO Script
|
|
tags: proxy_script
|
|
block:
|
|
- name: Copy Squid GPO Script
|
|
vars:
|
|
proxy_vm: "{{ os_project }}-{{ win_project }}-proxy"
|
|
proxy_address: "{{ hostvars[proxy_vm].ansible_host }}:3128"
|
|
ansible.builtin.template:
|
|
src: "{{ squid_proxy_script_tmpl }}"
|
|
dest: "{{ script_dir }}\\{{ squid_proxy_script }}"
|
|
force: true
|
|
tags: copy_proxy_script
|
|
|
|
- name: Apply Squid GPO Script
|
|
win_shell: "powershell {{ script_dir }}\\{{ squid_proxy_script }}"
|
|
tags: create_proxy_gpo
|
|
when: |
|
|
inventory_hostname in groups['meta-name_dc01'] and
|
|
project_zone == 'protected'
|