- name: ensure that the unarchive utils tar relies upon for file extraction are available (CentOS/RHEL)
  yum: name={{ item }} state=latest
  with_items:
  - bzip2
  - unzip
  when: ansible_os_family == "RedHat"

- name: ensure that the unarchive utils tar relies upon for file extraction are available (Debian/Ubuntu)
  apt: name={{ item }} state=latest
  with_items:
  - bzip2
  - unzip
  when: ansible_os_family == "Debian"

- name: create temporary build directory
  shell: mktemp -d
  register: tempdir

- name: copy the Dockerfile
  template: src=Dockerfile dest="{{ tempdir.stdout }}/"

- name: copy the authorization config file
  template: src=d4s.authorization dest="{{ tempdir.stdout }}/" mode=0644
 
- name: Build the docker image
  docker_image:
    path: "{{ tempdir.stdout }}"
    name: "{{ image_name }}"
    tag: "{{ image_tag }}"

- name: remove the temporary build directory
  file: path="{{ tempdir.stdout }}" state=absent