Ensure $(hostname).local is in hosts file on WSL

This commit is contained in:
Kenneth Benzie 2022-11-06 10:56:19 +00:00
parent cee0c443a3
commit 1895f1561d

View File

@ -40,3 +40,21 @@
with_items: with_items:
- win_git.ps1 - win_git.ps1
- win_git.py - 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'