win_hosts – Manages hosts file entries on Windows
win_hosts – Manages hosts file entries on Windows
New in version 2.8.
Synopsis
- 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%system32driversetchosts.
Parameters
Parameter | Choices/Defaults | Comments |
---|---|---|
action - |
|
Controls the behavior of Only applicable when If If |
aliases - |
A list of additional names (cname records) for the host entry. Only applicable when | |
canonical_name - |
A canonical name for the host entry. required for | |
ip_address - |
The ip address for the host entry. Can be either IPv4 (A record) or IPv6 (AAAA record). Required for | |
state - |
|
Whether the entry should be present or absent. If only If only If |
Notes
Note
- Each canonical name can only be mapped to one IPv4 and one IPv6 address. If
canonical_name
is provided withstate=present
and is found to be mapped to another IP address that is the same type as, but unique fromip_address
, thencanonical_name
and allaliases
will be removed from the entry and added to an entry with the provided IP address. - Each alias can only be mapped to one canonical name. If
aliases
is provided withstate=present
and an alias is found to be mapped to another canonical name, then the alias will be removed from the entry and added to or removed from (based on action) an entry with the provided canonical name. - See also win_template, win_file, win_copy
Examples
- 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
Status
- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Community. [community]
Authors
- Micah Hunsberger (@mhunsber)
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.8/modules/win_hosts_module.html