# How to make Ansible Tasks work with Packer

**URL:** <https://forum.ansible.com/t/how-to-make-ansible-tasks-work-with-packer/30069>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [April 4, 2019, 9:27pm UTC](https://forum.ansible.com/t/how-to-make-ansible-tasks-work-with-packer/30069 "2019-04-04T21:27:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [April 4, 2019, 9:27pm UTC](https://forum.ansible.com/t/how-to-make-ansible-tasks-work-with-packer/30069/1 "2019-04-04T21:27:25Z")

</div>

Hello,

I’m trying to use Ansible as a provisioner with Packer. I have a playbook with tasks that:  
-create a local directory (win\_file)  
-download a file from s3 (aws\_s3)  
-run windows updates (win\_updates)

It works fine when I run it manually, but when I run it from Packer (Ansible provisioner), the only Task that works is the one to create a local directory. The other Tasks fail with generic error: “msg”: "Unexpected failure during module execution.

Is there a limit to which modules will work with Packer?  
Is there something special you need to do to make the modules work? I’m pretty new to Ansbile – thanks much for any help

- hosts: all

tasks:

- name: Create a directory

win\_file:

path: C:\updater

state: directory

- name: download chocolatey from s3 to control host

vars:

ansible\_python\_interpreter: /usr/bin/python3

aws\_s3:

bucket: launch-data

object: chocolatey.0.10.13.nupkg

dest: /home/ec2-user/chocolatey.0.10.13.nupkg

mode: get

delegate\_to: localhost

- name: copy chocolatey from control host to target host updater folder

win\_copy:

src: /home/ec2-user/chocolatey.0.10.13.nupkg

dest: C:\updater\chocolatey.0.10.13.nupkg

- name: run windows update

win\_updates:

category\_names:

- CriticalUpdates

- SecurityUpdates

state: installed

register: update\_result

- name: reboot host if required after updates

win\_reboot:

when: update\_result.reboot\_required

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [April 5, 2019, 2:24am UTC](https://forum.ansible.com/t/how-to-make-ansible-tasks-work-with-packer/30069/2 "2019-04-05T02:24:54Z")

</div>

There is no limitation which task can be run from packer.

Try adding -vvvv when you execute from packer and from outside of packer and compare the results

Regards  
Tony Chia

---

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [April 5, 2019, 5:20pm UTC](https://forum.ansible.com/t/how-to-make-ansible-tasks-work-with-packer/30069/3 "2019-04-05T17:20:36Z")

</div>

Thank You - Only the fist line is the same:

TASK [download chocolatey from s3 to control host] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
amazon-ebs: task path: /home/ec2-user/manual-builds/play-win2016-test2-pack.yaml:9  
after this the output is very different for each

I can see an actual error when the playbook is run from Packer:

amazon-ebs: File “/usr/local/lib/python3.7/site-packages/ansible/plugins/shell/ **init**.py”, line 210, in append\_command  
amazon-ebs: if self.\_SHELL\_AND:  
amazon-ebs: AttributeError: ‘ShellModule’ object has no attribute ‘\_SHELL\_AND’  
amazon-ebs: fatal: [default]: FAILED! =\> {  
amazon-ebs: “msg”: “Unexpected failure during module execution.”,

---

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [April 5, 2019, 10:21pm UTC](https://forum.ansible.com/t/how-to-make-ansible-tasks-work-with-packer/30069/4 "2019-04-05T22:21:45Z")

</div>

As it turns out I was able to work around this by using the win\_get\_url module instead of aws\_s3
