- name: create master
  sudo: true
  sudo_user: "{{ master_user }}"
  command: creates={{ buildmaster_dir }} buildbot create-master -r {{ buildmaster_dir }}

- name: upload master config
  sudo: true
  sudo_user: "{{ master_user }}"
  template: src={{ buildmaster_template }} dest={{ buildmaster_dir }}/master.cfg owner={{ master_user }} group={{ master_user }}

- name: check master config
  sudo: true
  sudo_user: "{{ master_user }}"
  command: buildbot checkconfig {{ buildmaster_dir }}

#- name: upgrade master
#  command: buildbot upgrade-master {{ buildmaster_dir }}

- name: generate buildmaster service file
  template: src=buildmaster.service.j2 dest=/lib/systemd/system/buildmaster.service owner=root group=root mode=0744

- name: start and enable buildmaster service
  service: name=buildmaster enabled=yes state=started

- name: reconfig master
  sudo: true
  sudo_user: "{{ master_user }}"
  command: buildbot reconfig {{ buildmaster_dir }}
