CircleCI Integration

The Bakery can build a new AMI for you every time your code changes - automatically and in the background.

Here is the flow:

  1. The developer writes code, commits it, and pushes it to a repository
  2. CircleCI is already configured to test the new code
  3. If the tests fail, then the developer is notified, and nothing more happens this round.
  4. If the tests pass, a notification is sent to the Bakery
  5. The Bakery then starts baking a new AMI with the new code


CircleCI has a configuration file called circle.yml. You can add a webhook URL to circleci.yml that sends a notification to the Bakery whenever a build is complete. Their documentation on Notifications is here:

The notification data is made available to be used by your Ansible playbook however you see fit. CircleCI sends quite a lot of information about the build (see the Example response). All of that data, including the really useful parts like vcs_revision are stored in a file called bakery_payload.yml. Your Ansible playbook should read that as a variable file.


Project to build

  1. Sign in to the Bakery using GitHub
  2. Go to your Pipelines
  3. Click on the Name of the Pipeline you want to trigger when your CircleCI job is built successfully
  4. Copy the CircleCI Webhook URL listed at the bottom
  5. Open the circle.yml configuration file
  6. Past in the following

  7. Save the circleci.yml file, commit it, but don't push it to the repository yet

Ansible playbook

  1. For your Ansible playbook to use the data sent by CircleCI, you will need to add a new line to your vars_file section. For example:

    yaml vars_files: - [ /tmp/ci/bakery_payload.yml, vars/defaults.yml ]

    Notice that the "bakery_payload.yml" file is outside your playbooks directory. It is in "/tmp" so will not be part of your final AMI.

  2. Since you may want to use your Ansible playbook outside of the Bakery, add a "defaults.yml" file and add whatever variables your playbook and roles are using to it.


On the application's code base:


## Bakery notification
    - url:

On your Ansible playbook's code base:


  - name: My Playbook
    sudo: True
    hosts: all
      - { role: base, tags: ['base'] }
      - { role: ruby, tags: ['ruby'] }
      - { role: code, tags: ['code'] }
      - { role: website, tags: ['website'] }
      - vars/{{ ansible_distribution }}.yml
      - [ /tmp/ci/bakery_payload.yml, vars/defaults.yml ]


  vcs_revision: master


  - name: Ensure the local git repo is updated with branch {{ vcs_revision }}
      version={{ vcs_revision }}
What do you think of this page? Tell us about it