Configure a Windows IIS Web Server
Configure a Windows host IIS (Internet Information Services) web server with an Ansible playbook.
We'll cover the following
Let’s configure a Windows host to run an IIS(Internet Information Services) web server with an Ansible playbook. You’ll perform the following steps:
- Create a new file named
configure_iis_web_server.yml
. - Add the
hosts
line targeting theall
group.
- Use
vars_prompts
to prompt for a username and password.
- Define the connection variables for a Windows host.
- Add the tasks list.
- Install the
web-server
feature and all subfeatures with thewin_feature
module.
win_feature
is an Ansible module used to install or uninstall roles or features for Windows servers. It requires the name
parameter, which is passed as a web-server
. web-server
is the Windows feature’s name to install IIS
.
include_management_tools
is specified and provided a value of yes
to install the management tools for IIS.
include_sub_features
is also provided a value of yes
. All the sub-features of the web-server
are also installed. state
indicates whether to install or uninstall. The value of the present
installs the feature.
- Create an
index.html
file.
- Copy the
index.html
to the remote Windows host.
The Ansible module win_copy
copies a file on the local host to a remote Windows location. Here are the parameters and their functions;
src
is the local path to the file. When a full path isn’t provided, the relative path is used.- The
dest
parameter specifies the location of the defaultindex.html
file forIIS
. - The parameter
force
is used to overwrite and replace the defaultindex.html
.
- Create a
logs
directory.
win_file
is used to create empty files, update file modifications of existing files, and/or to create directories.
path
is a required parameter used to specify the location of the logs
directory on the remote host. state
is set to directory
, which results in Ansible creating a directory.
- Install
dotnetcore
with no frameworks.
Chocolatey is a package manager for Windows that automates software installs. win_chocolatey
is the module for using Chocolatey with Ansible. This is a great example of how Ansible is more than just an automation tool. It’s an orchestration engine. Other automation technologies can also be plugged into Ansible to augment it.
You use win_chocolatey
to install the dotnetcore-windowshosting
package from the public Chocolatey feed. The module is given the version
parameter to lock the version installed to 3.1.0
. You provide several arguments as a value to the install_args
to install it with no frameworks.
Installing the dotnetcore-windowshosting
package requires a restart of IIS. The IIS restart should only occur after the install. IIS should not be restarted any time after the first install because it has the potential of causing an outage.
Running operations when a change occurs is accomplished by using the notify
module. The notify
module will trigger the restart IIS
handler only when the task reports a change.
- Use a handler to restart IIS.
A handler
is defined outside the tasks
list, in its own list in the YAML file. Each handler requires
- A name
- An action
The handler
named restart IIS
calls the win_shell
Ansible module to execute PowerShell on a remote Windows host. The command & {iisreset}
restarts IIS with the command-line utility.
- Review and run the final playbook and the
index.html
below:
/
- configure_iis_web_server.yml
Execute the following command in the terminal to execute the playbook.
- Verify the configuration by hitting the web server’s landing page.
/
- configure_iis_web_server.yml
- Run the playbook with verbosity set to
3
.
Click on the Run
button and wait for the environment to set up. Execute the playbook in the terminal.
In this lesson, you successfully configured an IIS
server on the Windows remote host using Ansible playbook.