main.yml 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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: "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