community.windows.win_hosts – Manages hosts file entries on Windows.¶
Note
This plugin is part of the community.windows collection (version 1.3.0).
To install it use: ansible-galaxy collection install community.windows
.
To use it in a playbook, specify: community.windows.win_hosts
.
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%\system32\drivers\etc\hosts.
Parameters¶
Notes¶
Note
Each canonical name can only be mapped to one IPv4 and one IPv6 address. If canonical_name is provided with
state=present
and is found to be mapped to another IP address that is the same type as, but unique from ip_address, then canonical_name and all aliases 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 with
state=present
and an alias is found to be mapped to another canonical name, then the alias will be removed from the entry and either added to or removed from (depending on action) an entry with the provided canonical name.
See Also¶
See also
- ansible.windows.win_template
The official documentation on the ansible.windows.win_template module.
- ansible.windows.win_file
The official documentation on the ansible.windows.win_file module.
- ansible.windows.win_copy
The official documentation on the ansible.windows.win_copy module.
Examples¶
- name: Add 127.0.0.1 as an A record for localhost
community.windows.win_hosts:
state: present
canonical_name: localhost
ip_address: 127.0.0.1
- name: Add ::1 as an AAAA record for localhost
community.windows.win_hosts:
state: present
canonical_name: localhost
ip_address: '::1'
- name: Remove 'bar' and 'zed' from the list of aliases for foo (192.168.1.100)
community.windows.win_hosts:
state: present
canonical_name: foo
ip_address: 192.168.1.100
action: remove
aliases:
- bar
- zed
- name: Remove hosts entries with canonical name 'bar'
community.windows.win_hosts:
state: absent
canonical_name: bar
- name: Remove 10.2.0.1 from the list of hosts
community.windows.win_hosts:
state: absent
ip_address: 10.2.0.1
- name: Ensure all name resolution is handled by DNS
community.windows.win_hosts:
state: absent
Authors¶
Micah Hunsberger (@mhunsber)