main.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ---
  2. - name: Create Namespace for Persistent Local Storage
  3. oc_project:
  4. name: "{{ persistentlocalstorage_project }}"
  5. node_selector: ""
  6. - name: Create temp directory for template
  7. command: mktemp -d /tmp/openshift-ansible-XXXXXXX
  8. register: g_persistentstorage_mktemp
  9. changed_when: false
  10. - template:
  11. src: local-persistent-volume-config.j2
  12. dest: "{{g_persistentstorage_mktemp.stdout}}/local-persistent-volume-config"
  13. changed_when: no
  14. - slurp:
  15. src: "{{g_persistentstorage_mktemp.stdout}}/local-persistent-volume-config"
  16. register: local_persistent_volume_config
  17. - name: Create ConfigMap for Persistent Local Storage Provisioner
  18. oc_obj:
  19. name: "local-volume-provisioner-config"
  20. namespace: "{{ persistentlocalstorage_project }}"
  21. kind: ConfigMap
  22. content:
  23. path: /tmp/cmplspout
  24. data: "{{ local_persistent_volume_config.content | b64decode | from_yaml }}"
  25. - name: Create ServiceAccount for Persistent Local Storage Provisioner
  26. oc_serviceaccount:
  27. name: "local-volume-provisioner"
  28. namespace: "{{ persistentlocalstorage_project }}"
  29. - name: Add SecurityContextContraint for Local Storage Provisioner
  30. oc_adm_policy_user:
  31. user: "system:serviceaccount:{{ persistentlocalstorage_project }}:local-volume-provisioner"
  32. namespace: "{{ persistentlocalstorage_project }}"
  33. resource_kind: scc
  34. resource_name: hostmount-anyuid
  35. state: present
  36. - name: Give rights to local-volume-provisioner to manage volumes
  37. oc_obj:
  38. state: present
  39. kind: ClusterRoleBinding
  40. name: local-storage:provisioner-pv-binding
  41. content:
  42. path: /tmp/crblvpout
  43. data:
  44. apiVersion: v1
  45. kind: ClusterRoleBinding
  46. metadata:
  47. name: local-storage:provisioner-pv-binding
  48. roleRef:
  49. apiGroup: rbac.authorization.k8s.io
  50. kind: ClusterRole
  51. name: system:persistent-volume-provisioner
  52. subjects:
  53. - kind: ServiceAccount
  54. name: local-volume-provisioner
  55. namespace: "{{ persistentlocalstorage_project }}"
  56. - name: Give rights to local-volume-provisioner to list nodes
  57. oc_obj:
  58. state: present
  59. kind: ClusterRoleBinding
  60. name: local-storage:provisioner-node-binding
  61. content:
  62. path: /tmp/ls-provnode
  63. data:
  64. apiVersion: v1
  65. kind: ClusterRoleBinding
  66. metadata:
  67. name: local-storage:provisioner-node-binding
  68. roleRef:
  69. apiGroup: rbac.authorization.k8s.io
  70. kind: ClusterRole
  71. name: system:node
  72. subjects:
  73. - kind: ServiceAccount
  74. name: local-volume-provisioner
  75. namespace: "{{ persistentlocalstorage_project }}"
  76. - name: Create Application Persistent Local Storage Provisioner
  77. oc_obj:
  78. kind: DaemonSet
  79. namespace: "{{ persistentlocalstorage_project }}"
  80. state: present
  81. name: local-volume-provisioner
  82. content:
  83. path: /tmp/plsprovout
  84. data:
  85. apiVersion: extensions/v1beta1
  86. kind: DaemonSet
  87. metadata:
  88. name: local-volume-provisioner
  89. spec:
  90. template:
  91. metadata:
  92. labels:
  93. app: local-volume-provisioner
  94. spec:
  95. containers:
  96. - env:
  97. - name: MY_NODE_NAME
  98. valueFrom:
  99. fieldRef:
  100. apiVersion: v1
  101. fieldPath: spec.nodeName
  102. - name: MY_NAMESPACE
  103. valueFrom:
  104. fieldRef:
  105. apiVersion: v1
  106. fieldPath: metadata.namespace
  107. - name: VOLUME_CONFIG_NAME
  108. value: local-volume-provisioner-config
  109. image: quay.io/external_storage/local-volume-provisioner:v1.0.1
  110. name: provisioner
  111. securityContext:
  112. runAsUser: 0
  113. volumeMounts:
  114. - mountPath: /mnt/local-storage
  115. name: local-storage
  116. serviceAccountName: local-volume-provisioner
  117. volumes:
  118. - hostPath:
  119. path: /mnt/local-storage
  120. name: local-storage