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

289 views
Skip to first unread message

Akim Grudzitsky

unread,
Nov 2, 2017, 12:03:32 PM11/2/17
to Ansible Project
I'm trying to install IIS server on the ec2 instance with Windows in AWS.
But getting an error:

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


Playbook:
--- # 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



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

Akim Grudzitsky

unread,
Nov 6, 2017, 6:31:09 PM11/6/17
to Ansible Project
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.



J Hawkesworth

unread,
Nov 7, 2017, 4:10:50 AM11/7/17
to Ansible Project

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

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

Akim Grudzitsky

unread,
Nov 7, 2017, 8:59:16 AM11/7/17
to Ansible Project
Hi Jon,

Thank you very much for the reply.

Sincerely,
Akim

Jordan Borean

unread,
Nov 7, 2017, 3:00:48 PM11/7/17
to Ansible Project
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

---
- name: provision new EC2 server
  hosts
: localhost
  gather_facts
: no
  tasks
:
 
- name: provision t2.micro EC2 instance
    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
   
register: ec2_details


 
- name: add new t2.micro EC2 instance to Windows group
    add_host
:
      name
: '{{item.public_ip}}'
      groups
: windows
    with_items
: '{{ec2_details.instances}}'


- name: install features on new EC2 server
  hosts
: windows
  gather_facts
: no
  tasks
:
 
- name: wait for connection to be online
    wait_for_connection
:

 
- name: install IIS Web-Server with sub features and management tools
    win_feature
:
      name
: Web-Server
      state
: present
      include_sub_features
: yes
      include_management_features
: yes
   
register: feature_install


 
- name: reboot if feature install requires it
    win_reboot
:
   
when: feature_install.reboot_required

Just a few notes about this

* Your inventory should contain an empty group calls windows that contains the connection vars required for it to connect. After provisioning the EC2 instance, add_host will add the public IP of the newly created instances to that group for the next play to work
* The 2nd play which runs on the windows group will first wait for the connection to be online, this will actively try and connect over WinRM and will fail if that is unsuccessful after a timeout
* The restart option of win_feature is deprecated, I've split it out into 2 tasks using the win_reboot action plugin.

Thanks

Jordan

Akim Grudzitsky

unread,
Nov 7, 2017, 3:08:38 PM11/7/17
to Ansible Project
OMG! Guys, thank you SO much!!!
I appreciate your help.
Reply all
Reply to author
Forward
0 new messages