HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Parallelising Packer with Ansible

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
withparallelisingansiblepacker

Problem

Issue

I have an Ansible role which covers Windows, macOS and Ubuntu OS. I also have a Packer template file for each OS (due to small nuances and changes in the template file to handle provisioning) which handles standing up and provisioning the VM with Ansible onto VSphere.

So to build all three VMs, it goes something like:

Windows build                Mac build                 Ubuntu build
---------------------     ---------------------      --------------------
| Packer -> Ansible | --> | Packer -> Ansible | ---> |Packer -> Ansible |
---------------------     ---------------------      --------------------


Which isn't very efficient and can take a while.

Solution

I'm thinking of parallelising this somehow, by potentially having Packer standup all three VMs, but not provision it - only get the IP address of the VMs, which then (with some manipulation), put the IP addresses into an Ansible inventory file, and the ansible playbook is then run against that.

Something like:

--------------
Packer -> | Windows VM |  |  macOS VM  |  | Ubuntu VM  | <----
          --------------     |
                             |
                          Ansible parallel provisioning


Is this an optimal way of using Packer and Ansible together? or is there a better way of parallelising these builds?

Solution

What about using a CI tool? Create a parallel job and the jobs will run parallel. For example, one could use Jenkins:

https://jenkins.io/blog/2017/09/25/declarative-1/

stage('run-parallel-branches') {
  steps {
    parallel(
      a: {
        echo "This is branch a"
      },
      b: {
        echo "This is branch b"
      }
    )
  }
}


but there are other CI tools that could do the same.

Code Snippets

stage('run-parallel-branches') {
  steps {
    parallel(
      a: {
        echo "This is branch a"
      },
      b: {
        echo "This is branch b"
      }
    )
  }
}

Context

StackExchange DevOps Q#3393, answer score: 1

Revisions (0)

No revisions yet.