main.yml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. - name: test if service accounts exists
  2. command: >
  3. {{ openshift.common.client_binary }} get sa {{ item }} -n {{ openshift_serviceaccounts_namespace }}
  4. with_items: openshift_serviceaccounts_names
  5. failed_when: false
  6. changed_when: false
  7. register: account_test
  8. - name: create the service account
  9. shell: >
  10. echo {{ lookup('template', '../templates/serviceaccount.j2')
  11. | from_yaml | to_json | quote }} | {{ openshift.common.client_binary }} create -f -
  12. when: item.1.rc != 0
  13. with_together:
  14. - openshift_serviceaccounts_names
  15. - account_test.results
  16. - name: test if scc needs to be updated
  17. command: >
  18. {{ openshift.common.client_binary }} get scc {{ item }} -o yaml
  19. changed_when: false
  20. failed_when: false
  21. register: scc_test
  22. with_items: openshift_serviceaccounts_sccs
  23. - name: Grant the user access to the privileged scc
  24. command: >
  25. {{ openshift.common.admin_binary }} policy add-scc-to-user
  26. privileged system:serviceaccount:{{ openshift_serviceaccounts_namespace }}:{{ item.0 }}
  27. when: "openshift.common.version_gte_3_1_or_1_1 and item.1.rc == 0 and 'system:serviceaccount:{{ openshift_serviceaccounts_namespace }}:{{ item.0 }}' not in {{ (item.1.stdout | from_yaml).users }}"
  28. with_nested:
  29. - openshift_serviceaccounts_names
  30. - scc_test.results
  31. ####
  32. #
  33. # Support for 3.0.z
  34. #
  35. ####
  36. - name: tmp dir for openshift
  37. file:
  38. path: /tmp/openshift
  39. state: directory
  40. owner: root
  41. mode: 700
  42. when: not openshift.common.version_gte_3_1_or_1_1
  43. - name: Create service account configs
  44. template:
  45. src: serviceaccount.j2
  46. dest: "/tmp/openshift/{{ item }}-serviceaccount.yaml"
  47. with_items: openshift_serviceaccounts_names
  48. when: not openshift.common.version_gte_3_1_or_1_1
  49. - name: Get current security context constraints
  50. shell: >
  51. {{ openshift.common.client_binary }} get scc privileged -o yaml
  52. --output-version=v1 > /tmp/openshift/scc.yaml
  53. changed_when: false
  54. when: not openshift.common.version_gte_3_1_or_1_1
  55. - name: Add security context constraint for {{ item }}
  56. lineinfile:
  57. dest: /tmp/openshift/scc.yaml
  58. line: "- system:serviceaccount:{{ openshift_serviceaccounts_namespace }}:{{ item }}"
  59. insertafter: "^users:$"
  60. with_items: openshift_serviceaccounts_names
  61. when: not openshift.common.version_gte_3_1_or_1_1
  62. - name: Apply new scc rules for service accounts
  63. command: "{{ openshift.common.client_binary }} update -f /tmp/openshift/scc.yaml --api-version=v1"
  64. when: not openshift.common.version_gte_3_1_or_1_1