diff options
author | heqnx <root@heqnx.com> | 2025-07-12 12:00:33 +0300 |
---|---|---|
committer | heqnx <root@heqnx.com> | 2025-07-12 12:00:33 +0300 |
commit | c8a6c4f60ed36e6d29461599695baa779aff4948 (patch) | |
tree | a6d4fc79e38067ea14c768c913ca1e22e3478865 /ansible/roles/proxmox_vm/tasks/set_network.yaml | |
parent | 6ec2eb61a02f9e55ef5b8d22a5ca61ca53ca05e7 (diff) | |
download | ansible-active-directory-range-c8a6c4f60ed36e6d29461599695baa779aff4948.tar.gz ansible-active-directory-range-c8a6c4f60ed36e6d29461599695baa779aff4948.zip |
adding a linux domain joined server
Diffstat (limited to 'ansible/roles/proxmox_vm/tasks/set_network.yaml')
-rw-r--r-- | ansible/roles/proxmox_vm/tasks/set_network.yaml | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/ansible/roles/proxmox_vm/tasks/set_network.yaml b/ansible/roles/proxmox_vm/tasks/set_network.yaml index 20ab31c..fb088ad 100644 --- a/ansible/roles/proxmox_vm/tasks/set_network.yaml +++ b/ansible/roles/proxmox_vm/tasks/set_network.yaml @@ -1,5 +1,5 @@ --- -- name: "vmid {{ clone_result.vmid }}: set up static ip address" +- name: "vmid {{ clone_result.vmid }}: 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 @@ -10,6 +10,56 @@ async: 15 poll: 0 delegate_to: "{{ vm_ip }}" + when: os_type == 'windows' + vars: + ansible_connection: "{{ win_connector }}" + ansible_user: "{{ default_win_username }}" + ansible_password: "{{ default_win_password }}" + ansible_port: "{{ win_port }}" + ansible_winrm_transport: basic + ansible_winrm_server_cert_validation: ignore + +- name: "vmid {{ vmid }}: configure network for linux" + block: + - name: "vmid {{ vmid }}: 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" + ansible.builtin.set_fact: + linux_interface_name: "{{ interface_result.stdout }}" + netplan_ip_address: "{{ ip }}" + + - name: "vmid {{ vmid }}: 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" + ansible.builtin.file: + path: "{{ item.path }}" + state: absent + loop: "{{ yaml_configs.files }}" + + - name: "vmid {{ vmid }}: 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" + ansible.builtin.command: netplan apply + async: 15 + poll: 0 + delegate_to: "{{ vm_ip }}" + when: os_type == 'linux' + vars: + ansible_connection: "{{ linux_connector }}" + ansible_user: "{{ default_linux_username }}" + ansible_password: "{{ default_linux_password }}" + ansible_port: "{{ linux_port }}" + ansible_host_key_checking: false - name: "vmid {{ clone_result.vmid }}: update ip to {{ ip }}" set_fact: |