- import_playbook: "/srv/web/infra/ansible/playbooks/include/happy_birthday.yml"
  vars:
    myhosts: "buildhw:bkernel"

- name: make koji builder(s) on raw hw
  hosts: buildhw:bkernel
  remote_user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"
  - import_tasks: "{{ tasks_path }}/osbs_certs.yml"

  - name: override nbde_client-network-flush to work around bug
    copy:
      src: "{{ files }}/common/nbde_client-network-flush"
      dest: /usr/bin/nbde_client-network-flush
      owner: root
      group: root
      mode: 755

  - name: tell NetworkManager we don't want any auto connections
    copy:
      src: "{{ files }}/common/noautodefault.conf"
      dest: /etc/NetworkManager/conf.d/noautodefault.conf
      owner: root
      group: root
      mode: 644

  roles:
  - base
  - { role: nfs/client, mnt_dir: '/mnt/fedora_koji',  nfs_src_dir: "{{ koji_hub_nfs }}", when: koji_hub_nfs is defined }
  - role: nfs/client
    mnt_dir: '/mnt/koji/ostree'
    nfs_src_dir: 'fedora_ostree_content/ostree'
    when: env != 'staging' and 'runroot' in group_names

  - role: nfs/client
    mnt_dir: '/mnt/koji/compose/ostree'
    nfs_src_dir: 'fedora_ostree_content/compose/ostree'
    when: env != 'staging' and 'runroot' in group_names

  - role: nfs/client
    mnt_dir: '/mnt/koji/ostree'
    nfs_src_dir: 'fedora_ostree_content/ostree'
    when: env != 'staging' and 'runroot' in group_names

  - role: nfs/client
    mnt_dir: '/mnt/koji/compose/ostree'
    nfs_src_dir: 'fedora_ostree_content/compose/ostree'
    when: env != 'staging' and 'runroot' in group_names

  - role: nfs/client
    mnt_dir: '/mnt/koji/ostree'
    nfs_src_dir: 'fedora_ostree_content_stg/ostree'
    when: env == 'staging' and 'runroot' in group_names

  - role: nfs/client
    mnt_dir: '/srv/odcs'
    nfs_src_dir: 'fedora_odcs'
    when: env != 'staging' and 'runroot' in group_names

  - role: nfs/client
    mnt_dir: '/srv/odcs'
    nfs_src_dir: 'fedora_odcs_stg'
    when: env == 'staging' and 'runroot' in group_names

  - role: nfs/client
    mnt_dir: '/mnt/koji/compose/ostree'
    nfs_src_dir: 'fedora_ostree_content_stg/compose/ostree'
    when: env == 'staging' and 'runroot' in group_names

  - koji_builder
  - { role: bkernel, when: inventory_hostname.startswith('bkernel') }
  - { role: linux-system-roles.nbde_client, when: "inventory_hostname.startswith(('bkernel', 'buildhw-x86'))" }
  - { role: serial-console, when: "inventory_hostname.startswith(('bkernel', 'buildhw-x86'))" }
  - hosts
  - ipa/client
  - { role: sudo, when: not inventory_hostname.startswith('bkernel') }
  - role: keytab/service
    kt_location: /etc/kojid/kojid.keytab
    service: compile
  - role: keytab/service
    owner_user: root
    owner_group: root
    service: innercompose
    host: "odcs{{ env_suffix }}.fedoraproject.org"
    kt_location: /etc/kojid/secrets/odcs_inner.keytab
    when: env == "staging"

  tasks:
  - import_tasks: "{{ tasks_path }}/motd.yml"
    when: not inventory_hostname.startswith('bkernel')

  - name: make sure kojid is running
    service: name=kojid state=started enabled=yes

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"
