---
- name: ensure packages required for buildslave are installed
  dnf: name={{ item }} state=present
  with_items:
    - buildbot-worker
    - git
    - policycoreutils-python-utils
  when: ansible_cmdline.ostree is not defined and deployment_type in ['dev', 'stg']

###########
## TODO: remove when transition to buildbot 1.7 is complete
- name: ensure packages required for buildslave are installed
  dnf: name={{ item }} state=present
  with_items:
    - buildbot-slave
    - git
    - policycoreutils-python-utils
  when: ansible_cmdline.ostree is not defined and deployment_type in ['prod']
############

- name: ensure packages required for CI buildslave are installed
  dnf: name={{ item }} state=present
  with_items:
    - testcloud
    - mash
    - mock
    - koji
    - python-fedora
    - python-doit
    - python2-rpmfluff
    - rpmlint
    - koji
    - bodhi-client
    - python-virtualenv
    - gcc
    - libcurl-devel
    - rpm-build
    - pylint
    - python-pep8
    - moreutils
  when: (deployment_type in ['qa-stg']) and (ansible_cmdline.ostree is not defined)

- name: set the selinux fcontext type for the buildmaster_home to var_lib_t
  command: semanage fcontext -a -t var_lib_t "{{ slave_dir }}(/.*)?"
  when: deployment_type in ['qa-stg']

- name: add the buildslave user for taskotron
  user: name=buildslave
  when: deployment_type in ['local']

- name: add the buildslave user for ci
  user: name=buildslave groups=mock
  when: deployment_type in ['qa-stg']

- name: ensure needed groups exist
  group: name={{ item }}
  when: deployment_type in ['dev', 'stg', 'prod']
  with_items:
    - testcloud
    - taskotron

- name: ensure needed groups exist
  group: name={{ slaves_group }}
  when: slaves_group is defined and (deployment_type in ['dev', 'stg', 'prod'])

- name: create buildslaves home
  file:
    path: "{{ buildslaves_home }}"
    state: directory
    mode: 0755
  when: slaves is defined and (deployment_type in ['dev', 'stg', 'prod'])

- name: add buildslave users
  user: name={{ item.user }} group={{ slaves_group }} groups=testcloud,taskotron home={{ item.home }}
  with_items: "{{ slaves }}"
  when: slaves is defined and (deployment_type in ['dev', 'stg', 'prod'])

- name: set the selinux fcontext type for the buildslave dir to var_lib_t
  command: semanage fcontext -a -t var_lib_t "{{ item.dir }}"
  with_items: "{{ slaves }}"
  when: slaves is defined and deployment_type in ['qa-prod', 'qa-stg']

- name: make sure the selinux fcontext is restored
  command: restorecon -R "{{ item.home }}"
  with_items: "{{ slaves }}"
  when: slaves is defined and deployment_type in ['dev', 'stg', 'prod', 'qa-prod', 'qa-stg']
