iis_custom_headers

IIS Custom Headers

CI Platforms Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.

Add or remove global, custom HTTP headers from IIS web sites on Microsoft Windows Server.

Role Variables

The iis_custom_headers default variable defines which key and value to set for custom HTTP headers. If you wish to override it, you'll need to re-define all the headers that should be present or absent. Ansible will not merge your overridden variable with the defaults. The X-Frame-Options header is defined by the IETF in RFC7034 to improve web application security.

By default, Ansible will restart IIS at the end of the tasks because it usually assumes the win_shell execution results in a change; toggle iis_custom_headers_restart_iis to prevent the IIS restart.

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

The tasks rely on using Powershell's web server (IIS) administration cmdlets Add-WebConfigurationProperty and Remove-WebConfigurationProperty.

- 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 result will add customHeaders elements to the global XML configuration:

<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

  • IIS

Dependencies

None.

License

BSD

About

Add or remove global, custom headers from IIS web sites on Microsoft Windows.

Install
ansible-galaxy install deekayen/ansible-role-iis-custom-headers
GitHub repository
License
bsd-3-clause
Downloads
727
Owner
My initials spelled as a word - pronounced /dEE-kAY-En/