diff --git a/playbooks/post-install.yml b/playbooks/post-install.yml index c5c4ada..514a84f 100644 --- a/playbooks/post-install.yml +++ b/playbooks/post-install.yml @@ -6,4 +6,5 @@ tasks: - name: Give admin rights to nicolas command: oc adm policy add-cluster-role-to-user cluster-admin nicolas.masse@itix.fr - + roles: + - { name: 'hostpath-provisioner', tags: 'hostpath-provisioner' } diff --git a/roles/hostpath-provisioner/files/registry-storage-pvc.yaml b/roles/hostpath-provisioner/files/registry-storage-pvc.yaml new file mode 100644 index 0000000..b3a8138 --- /dev/null +++ b/roles/hostpath-provisioner/files/registry-storage-pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: registry-storage + namespace: default +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 5Gi diff --git a/roles/hostpath-provisioner/tasks/main.yml b/roles/hostpath-provisioner/tasks/main.yml new file mode 100644 index 0000000..8d801d4 --- /dev/null +++ b/roles/hostpath-provisioner/tasks/main.yml @@ -0,0 +1,39 @@ +--- + + - name: Create a directory for the hostpath-provisioner + file: state=directory path={{ hostpath_provisioner_path }} owner=root group=root mode=0777 setype=svirt_sandbox_file_t + + - name: Query existing deploymentconfigs + command: oc get daemonset -n "{{ hostpath_provisioner_target_namespace }}" -o name -l "name=hostpath-provisioner" + register: oc_get_daemonset + changed_when: false + + - name: Deploy app if needed + set_fact: + deploy_needed: "{{ 'daemonsets/hostpath-provisioner' not in oc_get_daemonset.stdout_lines }}" + + - name: Process the OpenShift Template and create the OpenShift objects for the hostpath-provisioner + shell: oc process -f "{{ hostpath_provisioner_template }}" -p "HOSTPATH_TO_USE={{ hostpath_provisioner_path }}" -p "TARGET_NAMESPACE={{ hostpath_provisioner_target_namespace }}" -p "HOSTPATH_PROVISIONER_IMAGE={{ hostpath_provisioner_docker_image }}" | oc create -f - + when: deploy_needed + register: oc + failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr + changed_when: oc.rc == 0 + + - name: Create a temporary directory to hold the PVC YAML file + tempfile: state=directory + register: tempfile + + - name: Copy the PersistentVolumeClaim object definition + copy: src=registry-storage-pvc.yaml dest={{tempfile.path}}/registry-storage-pvc.yaml + when: hostpath_provisioner_patch_docker_registry + + - name: Create a PersistentVolumeClaim for the docker-registry + command: oc create -n default -f {{tempfile.path}}/registry-storage-pvc.yaml + when: hostpath_provisioner_patch_docker_registry + register: oc + failed_when: oc.rc > 0 and 'Error from server (AlreadyExists):' not in oc.stderr + changed_when: oc.rc == 0 + + - name: Add the new volume to docker-registry + command: oc volume dc docker-registry -n default --add=true --overwrite=true --type=persistentVolumeClaim --name=registry-storage --claim-name=registry-storage + when: hostpath_provisioner_patch_docker_registry diff --git a/roles/hostpath-provisioner/vars/main.yml b/roles/hostpath-provisioner/vars/main.yml new file mode 100644 index 0000000..b5cf52f --- /dev/null +++ b/roles/hostpath-provisioner/vars/main.yml @@ -0,0 +1,7 @@ +--- + + hostpath_provisioner_path: /var/openshift + hostpath_provisioner_target_namespace: default + hostpath_provisioner_docker_image: nmasse/openshift-hostpath-provisioner:latest + hostpath_provisioner_template: https://raw.githubusercontent.com/nmasse-itix/OpenShift-HostPath-Provisioner/master/setup/hostpath-provisioner-template.yaml + hostpath_provisioner_patch_docker_registry: true