# fatal: \[localhost\]: FAILED! when installing IIS on Windows Server 2016 ec2

**URL:** <https://forum.ansible.com/t/fatal-localhost-failed-when-installing-iis-on-windows-server-2016-ec2/25902>\
**Category:** Ansible Project\
**Tags:** windows, aws\
**Created:** [November 2, 2017, 4:03pm UTC](https://forum.ansible.com/t/fatal-localhost-failed-when-installing-iis-on-windows-server-2016-ec2/25902 "2017-11-02T16:03:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akim\_Grudzitsky](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@Akim\_Grudzitsky](https://forum.ansible.com/u/Akim_Grudzitsky)\
**Post date:** [November 2, 2017, 4:03pm UTC](https://forum.ansible.com/t/fatal-localhost-failed-when-installing-iis-on-windows-server-2016-ec2/25902/1 "2017-11-02T16:03:32Z")

</div>

I’m trying to install IIS server on the ec2 instance with Windows in AWS.  
But getting an error:

```auto
fatal: [localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

```

Playbook:

```auto
--- # Install IIS Web-Server

- hosts: localhost
  connection: local
  remote_user: test
  become: yes
  gather_facts: no
  vars_files:
  - files/awscreds.yml
  tasks:
  - name: Basic provisioning of two t2.micro EC2 instances
    ec2:
      aws_access_key: "{{ aws_id }}"
      aws_secret_key: "{{ aws_key }}"
      region: "{{ aws_region }}"
      image: ami-e3bb7399
      instance_type: t2.micro
      count: 1
      vpc_subnet_id: subnet-112b2c3d
      assign_public_ip: yes
  - name: Install IIS Web-Server with sub features and management tools
    win_feature:
      name: Web-Server
      state: present
      restart: True
      include_sub_features: True
      include_management_tools: True

```

[![](https://lh3.googleusercontent.com/-g1J8NYzX2LE/WftBkl-BBWI/AAAAAAAAADE/_ZUO942rfgAt3dQqu0DTbyz0I7XJXsaGgCLcBGAs/s320/Ansible_Error_Playbook.png)](https://lh3.googleusercontent.com/-g1J8NYzX2LE/WftBkl-BBWI/AAAAAAAAADE/_ZUO942rfgAt3dQqu0DTbyz0I7XJXsaGgCLcBGAs/s1600/Ansible_Error_Playbook.png)

[![](https://lh3.googleusercontent.com/-s6QV2Rjnkoc/WftBpH-Cc8I/AAAAAAAAADI/6zry4eK_FtUQE8uYXBytJJuoau9tldCRQCLcBGAs/s320/Ansible_Error_Playbook_2.png)](https://lh3.googleusercontent.com/-s6QV2Rjnkoc/WftBpH-Cc8I/AAAAAAAAADI/6zry4eK_FtUQE8uYXBytJJuoau9tldCRQCLcBGAs/s1600/Ansible_Error_Playbook_2.png)

Could you please advise how to fix this?  
Thank you.

---

<div class="post-metadata">

**Author:** ![Akim\_Grudzitsky](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@Akim\_Grudzitsky](https://forum.ansible.com/u/Akim_Grudzitsky)\
**Post date:** [November 6, 2017, 11:31pm UTC](https://forum.ansible.com/t/fatal-localhost-failed-when-installing-iis-on-windows-server-2016-ec2/25902/2 "2017-11-06T23:31:09Z")

</div>

I updated the playbook. I added a second play to target the new Windows host and some further steps after the `ec2` module to add the new host to the inventory.

However, I’m still getting the same error. The task is failing.

**Updated Playbook:**

— # EC2 MODULE - PROVISIONING EXAMPLE

- hosts: localhost

connection: local

remote\_user: test

become: yes

gather\_facts: no

vars\_files:

- files/awscreds.yml

tasks:

- name: Provision of a set of Windows instances

ec2:

aws\_access\_key: “{{ aws\_id }}”

aws\_secret\_key: “{{ aws\_key }}”

region: “{{ aws\_region }}”

image: ami-e3bb7399

instance\_type: t2.micro

count: 1

vpc\_subnet\_id: subnet-112b2c3d

assign\_public\_ip: yes

count\_tag:

Name: CountTagDemo

instance\_tags:

Name: WinDemo

register: ec2

- name: Print the results

debug: var=item

with\_items: ec2.instances

- name: Add all instance public IPs to host group

add\_host: hostname={{ item.public\_ip }} groups=windows

with\_items: “{{ ec2.instances }}”

- name: Wait for the instances to boot

wait\_for: state=started

with\_items: ec2.instances

- hosts: windows

connection: local

remote\_user: test

become: yes

gather\_facts: no

vars\_files:

- files/awscreds.yml

tasks:

- name: Install IIS

win\_feature:

name: “Web-Server”

state: present

restart: true

include\_sub\_features: yes

include\_management\_tools: yes

**Error Message:**

TASK [Install IIS] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

**task path: /home/test/Playbooks/awsec2win\_provision.yml:47**

Using module file /usr/lib/python2.7/site-packages/ansible-2.5.0-py2.7.egg/ansible/modules/windows/win\_feature.py

\<\> ESTABLISH LOCAL CONNECTION FOR USER: test

\<\> EXEC /bin/sh -c ‘echo ~ && sleep 0’

\<\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149`” && echo ansible-tmp-1510010700.13-143481769279149=“`echo /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149`” ) && sleep 0’

\<\> PUT /tmp/tmpfvOE2z TO /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149/win\_feature.py

\<\> PUT /tmp/tmpzqtpyD TO /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149/args

\<\> EXEC /bin/sh -c ‘chmod u+x /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149/ /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149/win\_feature.py /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149/args && sleep 0’

\<\> EXEC /bin/sh -c ‘sudo -H -S -n -u root /bin/sh -c ‘"’“‘echo BECOME-SUCCESS-fsnrdknpojaqmlsccnjclmrmrbdzokmc; /usr/bin/python /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149/win\_feature.py /home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149/args; rm -rf “/home/test/.ansible/tmp/ansible-tmp-1510010700.13-143481769279149/” \> /dev/null 2\>&1’”’"’ && sleep 0’

fatal: : FAILED! =\> {

“changed”: false,

“failed”: true,

“module\_stderr”: “”,

“module\_stdout”: “”,

“msg”: “MODULE FAILURE”,

“rc”: 0

}

to retry, use: --limit @/home/test/Playbooks/awsec2win\_provision.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

: ok=0 changed=0 unreachable=0 failed=1

localhost : ok=4 changed=2 unreachable=0 failed=0

Could you please advise if the playbook is correct or how it should be modified to install IIS server?  
Thank you.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 7, 2017, 9:10am UTC](https://forum.ansible.com/t/fatal-localhost-failed-when-installing-iis-on-windows-server-2016-ec2/25902/3 "2017-11-07T09:10:50Z")

</div>

I don’t use ec2 but I think having the ‘connection: local’ for your windows hosts is causing you problems, as it appears to be attempting to use the win\_feature.py (documentation) instead of the win\_feature.ps1 (actual windows module code).  
The connection type for windows hosts, at the moment anyway, has to be winrm, otherwise ansible will default to assuming it can use python modules.

I think you are almost there, but will need to make sure when you hit the

hosts: windows

(new play in your playbook) you have got the all the windows connection settings set up in your group\_vars. I don’t know what you would need to do to discover the correct username and password to connect (probably as Administrator user) to your new ec2 host, but those settings will need to be set up by that point. See this bit of the documentation for the windows-specific variables that you need to set up in your inventory / group\_vars: [http://docs.ansible.com/ansible/latest/intro\_windows.html#inventory](http://docs.ansible.com/ansible/latest/intro_windows.html#inventory)

Once you have that figured out, I’d recommend using ‘wait\_for\_connection’ module to make sure that you can actually connect to your new instance, probably with a bit of a wait period to give the machine time to boot up and complete start up activities. wait\_for\_connection is pretty smart and assuming your inventory/group\_vars are configured ok will test that you can make a winrm connection for windows hosts (and ssh or whatever other transport for non-windows hosts).

Bear in mind too that Web-Server is a pretty big feature and I have seen it take nearly 5 minutes to install (on s2012r2) so given your t2.micro instance is 1 cpu it may take a while to complete.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Akim\_Grudzitsky](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@Akim\_Grudzitsky](https://forum.ansible.com/u/Akim_Grudzitsky)\
**Post date:** [November 7, 2017, 1:59pm UTC](https://forum.ansible.com/t/fatal-localhost-failed-when-installing-iis-on-windows-server-2016-ec2/25902/4 "2017-11-07T13:59:16Z")

</div>

Hi Jon,

Thank you very much for the reply.

Sincerely,  
Akim

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [November 7, 2017, 8:00pm UTC](https://forum.ansible.com/t/fatal-localhost-failed-when-installing-iis-on-windows-server-2016-ec2/25902/5 "2017-11-07T20:00:47Z")

</div>

As Jon is saying you are trying to run the win\_feature module on localhost and not the newly provisioned EC2 server. Here is a very mock playbook that you need to follow to get working. Note this is not tested and some things could potentially be wrong

`

---

<div class="post-metadata">

**Author:** ![Akim\_Grudzitsky](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@Akim\_Grudzitsky](https://forum.ansible.com/u/Akim_Grudzitsky)\
**Post date:** [November 7, 2017, 8:08pm UTC](https://forum.ansible.com/t/fatal-localhost-failed-when-installing-iis-on-windows-server-2016-ec2/25902/6 "2017-11-07T20:08:38Z")

</div>

OMG! Guys, thank you SO much!!!  
I appreciate your help.
