Ansible provisioners

Hello. I have a quick question, new to how Packer works, read the documentation but it did not really help me with this. I am trying to better understand how I can tie in Ansible as part of a provisioning step in building images.

If I want to run an Ansible playbook as a “provisioner” and I can’t reach an Ansible controller, is it possible to run the Ansible playbooks locally on my workstation?

What is the best approach to doing that? Do I need to point it to a controller? Do I have to install Ansible on the target machine first and push the playbook files somehow to the target I am building?

I want to try and “bake-in” as much as I can to the image before rolling it out. I know I can run some CI-CD tools after, again trying to get as much pre-configured as possible.

Any advice would be greatly appreciated. Thank you.

Anyone have some tips or advice on this? Thank you very much.

Hello Larry!

If you are familiar with Ansible, perhaps the best will be start using ansible-local provisioner.

In this way you can have:

  • packer building an image, say ubuntu
  • packer running a provisioner shell, you install ansible
  • packer running a provisioner ansible-local, and this will run on the VM.

A simple example is here:

Let me know how this goes.

Thanks
Alvaro

You can look at this example that I made to demo hardening Centos6 to DISA-STIG standards https://github.com/bbaassssiiee/vagransible This runs Packer locally on a Mac.

A more complex example ishttps://github.com/bbaassssiiee/redesign