---
- name: K8s customization
  hosts: master
  become: true
  tasks:
    - name: Git clone local-path-provisioner
      git:
        repo: https://github.com/rancher/local-path-provisioner.git
        dest: "/root/git-local-path-provisioner"
        clone: yes
        update: no
        version: v0.0.26
    - name: Local path provisioner configuration
      copy:
        dest: /tmp/local-path-provisioner.yaml
        mode: 0644
        content: |
          storageClass:
            defaultClass: false
            defaultVolumeType: hostPath
            name: local-path
          nodePathMap:
            - node: DEFAULT_PATH_FOR_NON_LISTED_NODES
              paths:
                - /scratch
    - name: Local path provisioner deployment
      vars:
        config: >-
          --namespace local-path-storage
          -f /tmp/local-path-provisioner.yaml
          local-path-storage
          /root/git-local-path-provisioner/deploy/chart/local-path-provisioner/
      shell: |-
        helm status --namespace local-path-storage local-path-storage
        if [ $? -ne 0 ]; then
            helm install {{ config }}
        else
            helm upgrade {{ config }}
        fi
      environment:
        KUBECONFIG: /etc/kubernetes/admin.conf
        PATH: /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
      when: true
