deekayen.iis_custom_headers
IIS Custom Headers
This document is about adding or removing custom HTTP headers for IIS (Internet Information Services) on Microsoft Windows Server.
Role Variables
The default variable iis_custom_headers
specifies the custom HTTP headers to set. If you want to change it, you need to list all the headers you want to keep or remove. Note that Ansible will not combine your changes with the defaults. The X-Frame-Options
header is a security feature defined by the IETF.
By default, Ansible will restart IIS after the tasks are completed because it assumes that changes were made. If you want to prevent this restart, set iis_custom_headers_restart_iis
to false.
Example of Custom Headers Configuration:
iis_custom_headers:
- { name: "X-Frame-Options", value: "SAMEORIGIN", state: "present" }
- { name: "X-Powered-By", value: "ASP", state: "absent" }
- { name: "X-Powered-By", value: "ASP.NET", state: "absent" }
iis_custom_headers_restart_iis: True
Example Playbook
This playbook shows how to use PowerShell commands to manage IIS headers.
- hosts: iis_servers
roles:
- role: deekayen.iis_custom_headers
iis_custom_headers:
- { name: "Strict-Transport-Security", value: "max-age=31536000", status: "present" }
- { name: "X-Frame-Options", value: "SAMEORIGIN", status: "present" }
- { name: "X-Powered-By", value: "ASP.NET", status: "absent" }
The outcome will add custom headers into the global XML configuration of IIS:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000" />
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Requirements
- Must have IIS installed.
Dependencies
None.
License
BSD
Add or remove global, custom headers from IIS web sites on Microsoft Windows.
ansible-galaxy install deekayen.iis_custom_headers