---

- hosts: nodes
  serial: 1
  vars: 
    vendor_name: openshift.io
    driver_name: cifs
    driver_location: "{{ playbook_dir }}/../anslib/openshift-flexvolume-cifs/flexvolume-driver/cifs"
    volume_plugin_path: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec"
    openshift_node_service: origin-node
    install_packages:
      - cifs-utils
  tasks:
    - name: Install required packages
      package:
        name: "{{ install_packages }}"
        state: present
    - name: Validate driver exists
      stat:
        path: "{{ driver_location }}"
      register: driver_exists
      delegate_to: localhost
    - name: Fail if driver not found
      fail:
        msg: Driver file not found!
      when: not driver_exists.stat.exists
    - name: Create cifs driver directory
      file:
        state: directory
        path: "{{ volume_plugin_path }}/{{ vendor_name }}~{{ driver_name }}"
    - name: Copy cifs driver
      copy:
        src: "{{ driver_location }}"
        dest: "{{ volume_plugin_path }}/{{ vendor_name }}~{{ driver_name }}/{{ driver_name }}"
        mode: 0755
      register: driver_copy
    - name: Restart OpenShift Node Service
      service:
        name: "{{ openshift_node_service }}"
        state: restarted