- name: set root passwd
  action: user name=root password={{ builder_rootpw }} state=present

- name: add mock user as 425
  action: user name=mock uid=425 state=present home=/var/lib/mock createhome=yes system=yes
- name: make mock homedir 2775
  action: file state=directory path=/var/lib/mock mode=2775 owner=mock group=mock
- name: add mock ssh dir
  action: file state=directory path=/var/lib/mock/.ssh mode=700 owner=mock group=mock
- name: add mock ssh keys
  action: copy src="{{ files }}/../roles/koji_builder/files//mock_auth_keys" dest=/var/lib/mock/.ssh/authorized_keys mode=644 owner=mock group=mock

- name: add ftpsync group
  action: group name=ftpsync gid=263 system=yes state=present

- name: add ftpsync user
  user: name=ftpsync uid=263 group=ftpsync createhome=yes system=yes state=present

- name: add the ftpsync update-fullfilelist script
  action: copy src=update-fullfilelist dest=/usr/local/bin/update-fullfilelist owner=ftpsync group=ftpsync mode=555

- name: add masher group
  action: group name=masher gid=751 system=yes state=present
# masher user 751
- name: add masher user as 751 - and group
  action: user name=masher uid=751 group=masher home=/home/masher groups=mock,ftpsync
# masher ssh keys and config
- name: add masher ssh dir
  action: file state=directory path=/home/masher/.ssh mode=700 owner=masher group=masher
- name: add masher ssh keys
  action: copy src="mash/masher.{{ item }}" dest="/home/masher/.ssh/{{ item }}" mode=600 owner=masher group=masher
  with_items:
    - id_rsa.pub
    - config

- name: add masher ssh priv key
  action: copy src="{{ private }}/files/mash/masher.id_rsa" dest=/home/masher/.ssh/id_rsa mode=600 owner=masher group=masher

- name: add masher koji cert/key
  action: copy src="{{ private }}/files/mash/masher.pem" dest=/home/masher/.fedora.cert mode=600 owner=masher group=masher
- name: add masher koji ca cert
  action: copy src="{{ private }}/files/koji/buildercerts/fedora-ca.cert" dest=/home/masher/.fedora-server-ca.cert

- name: copy over our mash.conf
  template: src=mash.conf dest=/etc/mash/mash.conf

# rawhide group
- name: rawhide group
  action: group name=rawhide gid=265
# rawhide user 265
- name: add rawhide user
  action: user name=rawhide uid=265 group=rawhide home=/tmp comment="rawhide compose account"
 
- name: make a bunch of dirs
  action: file state=directory path={{ item }}
  with_items:
    - /pub
    - /pub/fedora
    - /pub/epel
    - /pub/alt
    - /epel
    - /mnt/fedora_koji
    - /var/spool/rsyslog

- name: add pkgs
  action: yum  state=present pkg={{ item }}
  with_items:
    - yum-utils
    - koji
    - strace
    - mock
    - nfs-utils
    - git
    - mash
    - intltool
    - mutt
    - koji
    - createrepo
    - pykickstart
    - pyliblzma
    - httpd

- name: /etc/koji/koji.conf
  action: copy src="{{ files }}//../roles/koji_builder/files/koji.conf" dest=/etc/koji.conf


# mock configs
- name: put extra special  mock configs in
  template: src="{{ item }}" dest="/etc/mock/{{ item }}" mode=644
  with_items:
    - fedora-branched-compose-armhfp.cfg
    - fedora-rawhide-compose-armhfp.cfg
    - fedora-branched-compose-i386.cfg
    - fedora-rawhide-compose-i386.cfg
    - fedora-branched-compose-x86_64.cfg
    - fedora-rawhide-compose-x86_64.cfg


# idmapd and make sure it's set to run
- name: idmapd.conf
  action: copy src="{{ files }}/../roles/koji_builder/files//idmapd.conf" dest=/etc/idmapd.conf
  tags:
  - configs

- name: make a mnt/koji link
  action: file state=link src=/mnt/fedora_koji/koji dest=/mnt/koji

- name: symlink /srv/pungi
  action: file src=/mnt/fedora_koji/compose dest=/srv/pungi  state=link

- name: add pkgs for nightly compose
  action: yum  state=present pkg={{ item }}
  with_items:
    - packagedb-cli
  when: inventory_hostname.startswith('branched-composer') or inventory_hostname.startswith('rawhide-composer') or inventory_hostname.startswith('composer.stg')

# put cron job in for branched compose
- name: branched compose cron
  action: copy src="branched" dest=/etc/cron.d/branched
  when: inventory_hostname.startswith('branched-composer')

# put cron job in for rawhide compose
- name: rawhide compose cron
  action: copy src="rawhide" dest=/etc/cron.d/rawhide
  when: inventory_hostname.startswith('rawhide-composer')

- name: sudoers defaults
  action: copy src="{{ private }}/files/sudo/releng-sudoers" dest=/etc/sudoers mode=0440
  tags:
  - configs
- name: sudoers for ftpsync
  action: copy src="{{ private }}/files/sudo/ftpsync-sudo" dest=/etc/sudoers.d/ftpsync mode=0440
  tags:
  - configs

- name: install compose /etc/httpd/conf.d/compose.conf file
  copy: >
    src="compose.conf"
    dest="/etc/httpd/conf.d/compose.conf"
    owner=root
    group=root
    mode=0644
  notify:
  - restart httpd
  tags:
  - config
  when: inventory_hostname.startswith('compose-x86-02')
