How to make Ansible Tasks work with Packer

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

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

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.”,

As it turns out I was able to work around this by using the win_get_url module instead of aws_s3