diff options
Diffstat (limited to 'ansible')
21 files changed, 57 insertions, 60 deletions
diff --git a/ansible/main.yaml b/ansible/main.yaml index 3c0effe..f3e6013 100644 --- a/ansible/main.yaml +++ b/ansible/main.yaml @@ -2,14 +2,14 @@ hosts: localhost gather_facts: no tasks: - - name: deploy main domain controller vm on proxmox + - name: "deploy {{ main_dc01_hostname }}.{{ main_domain_name }} vm on {{ proxmox_hostname }}" include_role: name: proxmox_vm vars: os_type: "windows" template: "{{ windows_server_template_name }}" id: "{{ windows_server_template_id }}" - vm: "{{ main_dc01_hostname }}" + vm: "{{ main_dc01_hostname }}.{{ main_domain_name }}" newid: "{{ main_dc01_vmid }}" vmid: "{{ main_dc01_vmid }}" ip: "{{ main_dc01_ip_address }}" @@ -19,7 +19,7 @@ domain: "{{ main_domain_name }}" fqdn: "{{ main_dc01_hostname }}.{{ main_domain_name }}" - - name: add domain controller vm to in-memory inventory + - name: "add {{ main_dc01_hostname }}.{{ main_domain_name }} to in-memory inventory" add_host: name: "{{ main_dc01_hostname }}.{{ main_domain_name }}" ansible_host: "{{ main_dc01_ip_address }}" @@ -31,14 +31,14 @@ ansible_winrm_server_cert_validation: ignore changed_when: false - - name: deploy linux domain vm on proxmox + - name: "deploy {{ main_linux_srv01_hostname }}.{{ main_domain_name }} vm on {{ proxmox_hostname }}" include_role: name: proxmox_vm vars: os_type: "linux" template: "{{ linux_server_template_name }}" id: "{{ linux_server_template_id }}" - vm: "{{ main_linux_srv01_hostname }}" + vm: "{{ main_linux_srv01_hostname }}.{{ main_domain_name }}" newid: "{{ main_linux_srv01_vmid }}" vmid: "{{ main_linux_srv01_vmid }}" ip: "{{ main_linux_srv01_ip_address }}" @@ -48,7 +48,7 @@ domain: "{{ main_domain_name }}" fqdn: "{{ main_linux_srv01_hostname }}.{{ main_domain_name }}" - - name: add linux domain vm to in-memory inventory + - name: "add {{ main_linux_srv01_hostname }}.{{ main_domain_name }} to in-memory inventory" add_host: name: "{{ main_linux_srv01_hostname }}.{{ main_domain_name }}" ansible_host: "{{ main_linux_srv01_ip_address }}" @@ -59,16 +59,16 @@ ansible_host_key_checking: false changed_when: false -- name: configure everything +- name: configure hosts hosts: all gather_facts: no tasks: - - name: configure windows dc + - name: "configure {{ main_dc01_hostname }}.{{ main_domain_name }}" include_role: name: dc01 when: inventory_hostname == main_dc01_hostname + '.' + main_domain_name - - name: configure linux server + - name: "configure {{ main_linux_srv01_hostname }}.{{ main_domain_name }}" include_role: name: srv01 when: inventory_hostname == main_linux_srv01_hostname + '.' + main_domain_name diff --git a/ansible/roles/dc01/tasks/cleanup.yaml b/ansible/roles/dc01/tasks/cleanup.yaml index e30df58..0e59407 100644 --- a/ansible/roles/dc01/tasks/cleanup.yaml +++ b/ansible/roles/dc01/tasks/cleanup.yaml @@ -1,3 +1,3 @@ -- name: "{{ ansible_host }}: execute cleanup.ps1" +- name: execute cleanup.ps1 ansible.windows.win_powershell: script: C:\scripts\cleanup.ps1 diff --git a/ansible/roles/dc01/tasks/init.yaml b/ansible/roles/dc01/tasks/init.yaml index afd2820..84b3c3e 100644 --- a/ansible/roles/dc01/tasks/init.yaml +++ b/ansible/roles/dc01/tasks/init.yaml @@ -1,3 +1,3 @@ -- name: "{{ ansible_host }}: execute init.ps1" +- name: execute init.ps1 ansible.windows.win_powershell: script: C:\scripts\init.ps1 diff --git a/ansible/roles/dc01/tasks/install_software.yaml b/ansible/roles/dc01/tasks/install_software.yaml index 4c43d2b..a5018a8 100644 --- a/ansible/roles/dc01/tasks/install_software.yaml +++ b/ansible/roles/dc01/tasks/install_software.yaml @@ -1,3 +1,3 @@ -- name: "{{ ansible_host }}: execute install-software.ps1" +- name: execute install-software.ps1 ansible.windows.win_powershell: script: C:\scripts\install-software.ps1 diff --git a/ansible/roles/dc01/tasks/populate_ad.yaml b/ansible/roles/dc01/tasks/populate_ad.yaml index 6eae140..e65ab64 100644 --- a/ansible/roles/dc01/tasks/populate_ad.yaml +++ b/ansible/roles/dc01/tasks/populate_ad.yaml @@ -1,4 +1,4 @@ -- name: "{{ ansible_host }}: execute populate-ad.ps1" +- name: execute populate-ad.ps1 ansible.windows.win_powershell: script: C:\scripts\populate-ad.ps1 parameters: diff --git a/ansible/roles/dc01/tasks/reboot.yaml b/ansible/roles/dc01/tasks/reboot.yaml index 6c17c3d..f36b168 100644 --- a/ansible/roles/dc01/tasks/reboot.yaml +++ b/ansible/roles/dc01/tasks/reboot.yaml @@ -1,3 +1,3 @@ -- name: "{{ ansible_host }}: reboot" +- name: reboot ansible.windows.win_reboot: reboot_timeout: 3600 diff --git a/ansible/roles/dc01/tasks/set_hostname.yaml b/ansible/roles/dc01/tasks/set_hostname.yaml index 73fa63c..5ad01b2 100644 --- a/ansible/roles/dc01/tasks/set_hostname.yaml +++ b/ansible/roles/dc01/tasks/set_hostname.yaml @@ -1,2 +1,2 @@ -- name: "{{ ansible_host }}: set hostname" +- name: set hostname ansible.windows.win_shell: Rename-Computer -NewName "{{ main_dc01_hostname }}" -Force diff --git a/ansible/roles/dc01/tasks/setup_domain.yaml b/ansible/roles/dc01/tasks/setup_domain.yaml index 778c4db..95c2066 100644 --- a/ansible/roles/dc01/tasks/setup_domain.yaml +++ b/ansible/roles/dc01/tasks/setup_domain.yaml @@ -1,4 +1,4 @@ -- name: "{{ ansible_host }}: execute setup-main-domain.ps1" +- name: execute setup-main-domain.ps1 ansible.windows.win_powershell: script: C:\scripts\setup-main-domain.ps1 parameters: diff --git a/ansible/roles/dc01/tasks/setup_gpo.yaml b/ansible/roles/dc01/tasks/setup_gpo.yaml index 53eb086..fc44130 100644 --- a/ansible/roles/dc01/tasks/setup_gpo.yaml +++ b/ansible/roles/dc01/tasks/setup_gpo.yaml @@ -1,4 +1,4 @@ -- name: "{{ ansible_host }}: execute setup-gpo.ps1 as domain admin" +- name: execute setup-gpo.ps1 as domain admin ansible.windows.win_command: powershell.exe -ExecutionPolicy Bypass -File C:\scripts\setup-gpo.ps1 -DomainName "{{ main_domain_name }}" become: yes become_method: runas diff --git a/ansible/roles/dc01/tasks/wait_for_ready.yaml b/ansible/roles/dc01/tasks/wait_for_ready.yaml index c43431c..b077e07 100644 --- a/ansible/roles/dc01/tasks/wait_for_ready.yaml +++ b/ansible/roles/dc01/tasks/wait_for_ready.yaml @@ -1,3 +1,3 @@ -- name: "{{ ansible_host }}: execute dc-wait-for-ready.ps1" +- name: execute dc-wait-for-ready.ps1 ansible.windows.win_powershell: script: C:\scripts\dc-wait-for-ready.ps1 diff --git a/ansible/roles/proxmox_vm/tasks/create_vm.yaml b/ansible/roles/proxmox_vm/tasks/create_vm.yaml index 21645b9..66f4cef 100644 --- a/ansible/roles/proxmox_vm/tasks/create_vm.yaml +++ b/ansible/roles/proxmox_vm/tasks/create_vm.yaml @@ -1,5 +1,4 @@ ---- -- name: "create vm from template" +- name: "create {{ fqdn }} from template" community.general.proxmox_kvm: api_host: "{{ proxmox_hostname }}" api_user: "{{ proxmox_username }}" diff --git a/ansible/roles/proxmox_vm/tasks/enable_qemu_guest_agent.yaml b/ansible/roles/proxmox_vm/tasks/enable_qemu_guest_agent.yaml index df6da92..f6ecd36 100644 --- a/ansible/roles/proxmox_vm/tasks/enable_qemu_guest_agent.yaml +++ b/ansible/roles/proxmox_vm/tasks/enable_qemu_guest_agent.yaml @@ -1,5 +1,4 @@ ---- -- name: "vmid {{ clone_result.vmid }}: enabling qemu guest agent via proxmox api" +- name: "{{ fqdn }} : enabling qemu guest agent via proxmox api" uri: url: "https://{{ proxmox_hostname }}:8006/api2/json/nodes/{{ proxmox_node }}/qemu/{{ clone_result.vmid }}/config" method: PUT diff --git a/ansible/roles/proxmox_vm/tasks/get_ip.yaml b/ansible/roles/proxmox_vm/tasks/get_ip.yaml index 584b44d..14a7e47 100644 --- a/ansible/roles/proxmox_vm/tasks/get_ip.yaml +++ b/ansible/roles/proxmox_vm/tasks/get_ip.yaml @@ -1,5 +1,4 @@ ---- -- name: "vmid {{ clone_result.vmid }}: getting config via proxmox api" +- name: "{{ fqdn }} : getting config via proxmox api" set_fact: vm_config: "{{ lookup('url', config_url, validate_certs=False, headers=config_headers) }}" vars: @@ -7,7 +6,7 @@ config_headers: Authorization: "PVEAPIToken={{ proxmox_username }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}" -- name: "vmid {{ clone_result.vmid }}: extracting ipv4 address" +- name: "{{ fqdn }}: extracting ipv4 address" set_fact: vm_ip: >- {{ @@ -20,10 +19,10 @@ | first }} -- name: "vmid {{ clone_result.vmid }}: ip address result" +- name: "{{ fqdn }}: ip address result" ansible.builtin.debug: - msg: "vmid {{ clone_result.vmid }} ip address is {{ vm_ip }}" + msg: "{{ fqdn }} ip address is {{ vm_ip }}" -- name: "vmid {{ clone_result.vmid }}: set ip to {{ vm_ip }}" +- name: "{{ fqdn }}: set ip to {{ vm_ip }}" set_fact: ansible_host: "{{ vm_ip }}" diff --git a/ansible/roles/proxmox_vm/tasks/main.yaml b/ansible/roles/proxmox_vm/tasks/main.yaml index 051e388..c6abe93 100644 --- a/ansible/roles/proxmox_vm/tasks/main.yaml +++ b/ansible/roles/proxmox_vm/tasks/main.yaml @@ -13,5 +13,5 @@ - name: set vm network configuration import_tasks: set_network.yaml - #- name: upload files to vm - # import_tasks: upload_files.yaml +- name: upload files to vm + import_tasks: upload_files.yaml diff --git a/ansible/roles/proxmox_vm/tasks/set_network.yaml b/ansible/roles/proxmox_vm/tasks/set_network.yaml index fb088ad..c75aa0f 100644 --- a/ansible/roles/proxmox_vm/tasks/set_network.yaml +++ b/ansible/roles/proxmox_vm/tasks/set_network.yaml @@ -1,5 +1,4 @@ ---- -- name: "vmid {{ clone_result.vmid }}: set up static ip address on windows" +- name: "{{ fqdn }} : set up static ip address on windows" win_shell: | Start-Transcript -Path C:\set_domain_network_log.txt -Append Get-NetIpAddress -InterfaceAlias 'Ethernet' | Remove-NetIPAddress -Confirm:$false @@ -19,36 +18,36 @@ ansible_winrm_transport: basic ansible_winrm_server_cert_validation: ignore -- name: "vmid {{ vmid }}: configure network for linux" +- name: "{{ fqdn }} : configure network for linux" block: - - name: "vmid {{ vmid }}: get default interface" + - name: "{{ fqdn }} : get default interface" ansible.builtin.shell: ip route get 8.8.8.8 | sed -n 's/.*dev \([^\ ]*\).*/\1/p' register: interface_result - - name: "vmid {{ vmid }}: set default interface variable" + - name: "{{ fqdn }} : set default interface variable" ansible.builtin.set_fact: linux_interface_name: "{{ interface_result.stdout }}" netplan_ip_address: "{{ ip }}" - - name: "vmid {{ vmid }}: find netplan configs in /etc/netplan" + - name: "{{ fqdn }} : find netplan configs in /etc/netplan" ansible.builtin.find: paths: /etc/netplan recurse: yes register: yaml_configs - - name: "vmid {{ vmid }}: remove all netplan configs in /etc/netplan" + - name: "{{ fqdn }} : remove all netplan configs in /etc/netplan" ansible.builtin.file: path: "{{ item.path }}" state: absent loop: "{{ yaml_configs.files }}" - - name: "vmid {{ vmid }}: set netplan static ip address" + - name: "{{ fqdn }} : set netplan static ip address" ansible.builtin.template: src: static_ip_netplan.yaml.j2 dest: /etc/netplan/01-netcfg.yaml mode: '0644' - - name: "vmid {{ vmid }}: apply netplan configuration" + - name: "{{ fqdn }} : apply netplan configuration" ansible.builtin.command: netplan apply async: 15 poll: 0 @@ -61,10 +60,10 @@ ansible_port: "{{ linux_port }}" ansible_host_key_checking: false -- name: "vmid {{ clone_result.vmid }}: update ip to {{ ip }}" +- name: "{{ fqdn }} : update ip to {{ ip }}" set_fact: ansible_host: "{{ ip }}" -- name: "vmid {{ clone_result.vmid }}: pause execution for 1 minute to allow ip change and reconnect" +- name: "{{ fqdn }} : pause execution for 3 minute to allow ip change and reconnect" pause: - minutes: 1 + minutes: 3 diff --git a/ansible/roles/proxmox_vm/tasks/start_vm.yaml b/ansible/roles/proxmox_vm/tasks/start_vm.yaml index f2ed036..67d2384 100644 --- a/ansible/roles/proxmox_vm/tasks/start_vm.yaml +++ b/ansible/roles/proxmox_vm/tasks/start_vm.yaml @@ -1,4 +1,4 @@ -- name: "start vm" +- name: "{{ fqdn }} : boot" community.general.proxmox_kvm: api_host: "{{ proxmox_hostname }}" api_user: "{{ proxmox_username }}" @@ -8,6 +8,6 @@ vmid: "{{ vmid | int }}" state: started -- name: "pause execution for 3 minutes to allow vm to fully boot" +- name: "{{ fqdn }} : pause execution for 3 minutes to allow vm to fully boot" pause: minutes: 3 diff --git a/ansible/roles/proxmox_vm/tasks/upload_files.yaml b/ansible/roles/proxmox_vm/tasks/upload_files.yaml index f2b9df8..007b321 100644 --- a/ansible/roles/proxmox_vm/tasks/upload_files.yaml +++ b/ansible/roles/proxmox_vm/tasks/upload_files.yaml @@ -1,5 +1,4 @@ ---- -- name: "upload directories" +- name: "{{ fqdn }} : upload directories" ansible.builtin.copy: src: "{{ item.src }}" dest: "{{ item.dest }}" diff --git a/ansible/roles/srv01/tasks/join_domain.yaml b/ansible/roles/srv01/tasks/join_domain.yaml index cd9b4f5..7f5796d 100644 --- a/ansible/roles/srv01/tasks/join_domain.yaml +++ b/ansible/roles/srv01/tasks/join_domain.yaml @@ -1,4 +1,4 @@ -- name: "{{ main_linux_srv01_hostname }}.{{ main_domain_name }}: execute join-domain.sh" +- name: execute join-domain.sh script: ../../../scripts/join-domain.sh -d "{{ main_domain_name }}" -n "{{ main_dc01_ip_address }}" -p "{{ default_win_password }}" args: executable: /bin/bash diff --git a/ansible/roles/srv01/tasks/reboot.yaml b/ansible/roles/srv01/tasks/reboot.yaml index 29ea4b0..d36ed0d 100644 --- a/ansible/roles/srv01/tasks/reboot.yaml +++ b/ansible/roles/srv01/tasks/reboot.yaml @@ -1,5 +1,3 @@ -- name: "{{ main_linux_srv01_hostname }}.{{ main_domain_name }}: reboot" - command: "shutdown -r now &" - async: 1 - poll: 0 - ignore_errors: true +- name: reboot + ansible.builtin.reboot: + reboot_timeout: 3600 diff --git a/ansible/roles/srv01/tasks/set_hostname.yaml b/ansible/roles/srv01/tasks/set_hostname.yaml index 40a9a8e..9141763 100644 --- a/ansible/roles/srv01/tasks/set_hostname.yaml +++ b/ansible/roles/srv01/tasks/set_hostname.yaml @@ -1,5 +1,9 @@ -- name: "{{ main_linux_srv01_hostname }}.{{ main_domain_name }}: update /etc/hosts" +- name: set hostname + ansible.builtin.hostname: + name: "{{ main_linux_srv01_hostname }}.{{ main_domain_name }}" + +- name: update /etc/hosts ansible.builtin.replace: path: /etc/hosts - regexp: "ubuntu-server2404" + regexp: "ubuntu" replace: "{{ main_linux_srv01_hostname }}.{{ main_domain_name }} {{ main_linux_srv01_hostname }}" diff --git a/ansible/scripts/join-domain.sh b/ansible/scripts/join-domain.sh index 24c87b0..7661acd 100644 --- a/ansible/scripts/join-domain.sh +++ b/ansible/scripts/join-domain.sh @@ -1,6 +1,6 @@ #!/bin/bash -[[ $EUID -ne 0 ]] && printf "%s\n" "run as root" && exit 1 +test "${EUID}" -ne 0 && printf "%s\n" "run as root" && exit 1 while getopts "d:n:p:" arg; do case $arg in @@ -10,11 +10,11 @@ while getopts "d:n:p:" arg; do esac done -DEBIAN_FRONTEND=noninteractive apt-get update -yqq &>/dev/null -DEBIAN_FRONTEND=noninteractive apt-get install -yqq realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit krb5-user &>/dev/null -DEBIAN_FRONTEND=noninteractive apt-get autoremove --purge -yqq &>/dev/null -DEBIAN_FRONTEND=noninteractive apt-get clean &>/dev/null -DEBIAN_FRONTEND=noninteractive apt-get autoclean &>/dev/null +DEBIAN_FRONTEND=noninteractive apt-get update -y +DEBIAN_FRONTEND=noninteractive apt-get install -y realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit krb5-user +DEBIAN_FRONTEND=noninteractive apt-get autoremove --purge -y +DEBIAN_FRONTEND=noninteractive apt-get clean +DEBIAN_FRONTEND=noninteractive apt-get autoclean if systemctl is-active systemd-resolved; then systemctl disable --now systemd-resolved --no-pager |