---
- name: install tftp server package
  package: state=present name=tftp-server
  tags:
  - packages
  - tftp_server

- name: install syslinux package
  package: state=present name=syslinux
  tags:
  - packages
  - tftp_server

- name: setup pxelinux.cfg dir
  file: path=/var/lib/tftpboot/pxelinux.cfg mode=755 state=directory
  tags:
  - config
  - tftp_server

- name: setup pxelinux.cfg default file
  copy: src=default.{{ inventory_hostname }} dest=/var/lib/tftpboot/pxelinux.cfg/default mode=644
  tags:
  - config
  - tftp_server
  when: datacenter != 'iad2' 

- name: enable tftp socket service
  service: state=started enabled=true name=tftp.socket
  tags:
  - service
  - config
  - tftp_server

- name: fill up the tftpboot directory
  synchronize: src="{{ bigfiles }}/tftpboot/" dest=/var/lib/tftpboot/
  tags:
  - tftp_server

- name: Set permissions on the rhcos tftpboot folder
  file: 
    path: /var/lib/tftpboot/rhcos
    mode: '0755'
  tags:
  - tftp_server
  when: datacenter == 'iad2' 

- name: Copy rhcos files to images folder
  copy:
    src: "/var/lib/tftpboot/rhcos/"
    dest: "/var/lib/tftpboot/images/RHCOS/4.8/x86_64/"
    remote_src: yes
  tags:
  - tftp_server
  when: datacenter == 'iad2'

# - name: generate custom configs
#   template: src=grubhost.cfg.j2 dest="/var/lib/tftpboot/uefi/{{ hostvars[item].install_mac }}"
#   with_items: "{{ groups['all'] }}"
#   when: "hostvars[item].install_noc == inventory_hostname"
#   tags:
#   - tftp_server
