Install Windows Server Roles and Features with Ansible

In this blog post, I will show you how to install Windows Server roles and features with Ansible.

With Ansible we can manage Windows server VM and physical hosts without installing an agent.

To complete this post and install roles and feature, please follow the requirements below:

Install Ansilble on a Linux Server (control host)

Manage Windows server with Ansible

Core Ansible Components

YAML

Below, is my YAML playbook file that I will use to install Windows IIS server 10 on my Windows Server 2019 VM.

---
- hosts: windows
 
  tasks:
    - name: Install IIS Server 10
      win_feature:
        name: Web-Server
        state: present

If you need to install more than one role or feature, see the code below on how to install multiple roles.

---
- hosts: windows
 
  tasks:
    - name: Install IIS Server 10
      win_feature:
        name:
          - Web-Server
          - Web-Mgmt-Console
        state: present

Before

Before running my playbook, I will check if IIS is on my VM and as you can see it is not.

Run Playbook

I will run my playbook using the following code.

ansible-playbook iis.yaml

When Ansible is installing something on a Windows server, you will see the following process running.

After a minute, I will recheck my server, and as you can see, IIS is available.

Processing…
Success! You're on the list.

Posted

in

by