Release tracking with Ansible

Justyna (@tramwaj29) set up Opbeat release tracking with Ansible, and was so kind to share how she did it.

If you’re working with Ansible, hopefully you’ll find this useful.

- name: get last commit rev
  shell: git log -n 1 --pretty=format:%H
  register: git_status
  delegate_to: localhost
  sudo: no
  tags:
    - opbeat

- name: get git branch
  shell: git rev-parse --abbrev-ref HEAD
  register: git_branch
  delegate_to: localhost
  sudo: no
  tags:
    - opbeat

- name: register opbeat release
  uri:
    url: 'https://intake.opbeat.com/api/v1/organizations/{{ opbeat_organization_id }}/apps/{{ opbeat_app_id }}/releases/'
    method: POST
    status_code: 202
    HEADER_Authorization: 'Bearer {{ opbeat_secret_token }}'
    HEADER_Content-Type: 'application/x-www-form-urlencoded'
    body: 'rev={{ git_status.stdout }}&branch={{ current_git_branch.stdout }}&status=completed'
  tags:
    - opbeat

Also, check out this blog post on the same topic by Danilo Bargen.

Thanks for sharing Justyna and Danilo!