# Using ansible to run AWS EC2ConfigService's sysprep

**URL:** <https://forum.ansible.com/t/using-ansible-to-run-aws-ec2configservices-sysprep/16429>\
**Category:** Ansible Project\
**Tags:** windows, aws\
**Created:** [October 4, 2014, 1:39pm UTC](https://forum.ansible.com/t/using-ansible-to-run-aws-ec2configservices-sysprep/16429 "2014-10-04T13:39:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Mounce](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@Peter\_Mounce](https://forum.ansible.com/u/Peter_Mounce)\
**Post date:** [October 4, 2014, 1:39pm UTC](https://forum.ansible.com/t/using-ansible-to-run-aws-ec2configservices-sysprep/16429/1 "2014-10-04T13:39:33Z")

</div>

I’m using Ansible to bake Windows AMIs in AWS. It works well.

This involves running `& "c:\program files\Amazon\Ec2ConfigService\ec2config.exe" -sysprep` as the last step. This will sysprep the box and then shut it down so that one can `aws ec2 create-image` on it.

Trouble is, because it shuts the box down, winrm goes with it.

I was thinking about how I might do this, and so far the best I’ve come up with is to schedule a task for a few seconds from now that will run that command. Ansible ought to get a good response from winrm and return ok.

Before I do that, can anyone think of something better, or has anyone done this already?

Regards  
Pete

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [October 5, 2014, 1:56am UTC](https://forum.ansible.com/t/using-ansible-to-run-aws-ec2configservices-sysprep/16429/2 "2014-10-05T01:56:41Z")

</div>

Hi Peter,

You probably want to do a “fire and forget” async task on the system, and then use the wait\_for module to determine when the system was done shutting down.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Peter\_Mounce](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@Peter\_Mounce](https://forum.ansible.com/u/Peter_Mounce)\
**Post date:** [October 5, 2014, 10:12am UTC](https://forum.ansible.com/t/using-ansible-to-run-aws-ec2configservices-sysprep/16429/3 "2014-10-05T10:12:29Z")

</div>

Thanks; that sounds way cleaner. I’ll try that.

---

<div class="post-metadata">

**Author:** ![M\_Ghaleb](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@M\_Ghaleb](https://forum.ansible.com/u/M_Ghaleb)\
**Post date:** [October 18, 2016, 6:46pm UTC](https://forum.ansible.com/t/using-ansible-to-run-aws-ec2configservices-sysprep/16429/4 "2016-10-18T18:46:04Z")

</div>

HI Peter,

have you managed to do it? I can not connect to the EC2 instance afterwards (after spinning up the AMI)

any success on that?

Regards,

M G

---

<div class="post-metadata">

**Author:** ![Peter\_Mounce](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@Peter\_Mounce](https://forum.ansible.com/u/Peter_Mounce)\
**Post date:** [October 19, 2016, 4:21pm UTC](https://forum.ansible.com/t/using-ansible-to-run-aws-ec2configservices-sysprep/16429/5 "2016-10-19T16:21:21Z")

</div>

Hi M G

[https://github.com/petemounce/ansible-modules-extras/blob/win\_ec2config/windows/win\_ec2config.ps1](https://github.com/petemounce/ansible-modules-extras/blob/win_ec2config/windows/win_ec2config.ps1) and [https://github.com/petemounce/ansible-modules-extras/blob/win\_ec2config/windows/win\_ec2config.py](https://github.com/petemounce/ansible-modules-extras/blob/win_ec2config/windows/win_ec2config.py) worked fine for me. There was a PR, but the contribution didn’t cover enough of the ec2config configuration surface area to be considered worth merging, and I didn’t have the bandwidth to make the additions at the time.

Best regards  
Pete
