ansible / ansible.builtin / v2.8.18 / module / win_hosts Manages hosts file entries on Windows. | "added in version" 2.8 of ansible.builtin" Authors: Micah Hunsberger (@mhunsber) preview | supported by communityansible.builtin.win_hosts (v2.8.18) — module
pip
Install with pip install ansible==2.8.18
Manages hosts file entries on Windows.
Maps IPv4 or IPv6 addresses to canonical names
Adds, removes, or sets cname records for ip and hostname pairs
Modifies %windir%\system32\drivers\etc\hosts.
- name: Add 127.0.0.1 as an A record for localhost win_hosts: state: present canonical_name: localhost ip_address: 127.0.0.1
- name: Add ::1 as an AAAA record for localhost win_environment: state: present canonical_name: localhost ip_address: '::1'
- name: Remove 'bar' and 'zed' from the list of aliases for foo (192.168.1.100) win_hosts: state: present canoncial_name: foo ip_address: 192.168.1.100 action: remove aliases: - bar - zed
- name: Remove hosts entries with canonical name 'bar' win_hosts: state: absent canonical_name: bar
- name: Remove 10.2.0.1 from the list of hosts win_hosts: state: absent ip_address: 10.2.0.1
- name: Ensure all name resolution is handled by DNS win_hosts: state: absent
state: choices: - absent - present default: present description: - Whether the entry should be present or absent. - If only C(canonical_name) is provided when C(state=absent), then all hosts entries with the canonical name of I(canonical_name) will be removed. - If only C(ip_address) is provided when C(state=absent), then all hosts entries with the ip address of I(ip_address) will be removed. - If C(ip_address) and C(canonical_name) are both omitted when C(state=absent), then all hosts entries will be removed. action: choices: - add - remove - set default: set description: - Controls the behavior of C(aliases). - Only applicable when C(state=present). - If C(add), each alias in I(aliases) will be added to the host entry. - If C(set), each alias in I(aliases) will be added to the host entry, and other aliases will be removed from the entry. aliases: description: - A list of additional names (cname records) for the host entry. - Only applicable when C(state=present). ip_address: description: - The ip address for the host entry. - Can be either IPv4 (A record) or IPv6 (AAAA record). - Required for C(state=present). canonical_name: description: - A canonical name for the host entry. - required for C(state=present).