diff --git a/roles/wsl/tasks/main.yaml b/roles/wsl/tasks/main.yaml index f633a80..82cf7c5 100644 --- a/roles/wsl/tasks/main.yaml +++ b/roles/wsl/tasks/main.yaml @@ -40,3 +40,21 @@ with_items: - win_git.ps1 - win_git.py + +- name: read /etc/resolv.conf file contents + set_fact: + resolv_conf: '{{lookup("ansible.builtin.file", "/etc/resolv.conf")}}' + +- name: get Windows host IP from /etc/resolv.conf + set_fact: + host_ip: '{{resolv_conf | regex_search("(\d+\.\d+\.\d+\.\d+)")}}' + +- name: add $(hostname).local to /etc/hosts + become: true + lineinfile: + path: /etc/hosts + regexp: '^{{host_ip | replace(".", "\.")}}' + line: '{{host_ip}} {{ansible_hostname}}.local' + owner: root + group: root + mode: '0644'