main.yml 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. - name: tmp dir for openshift
  2. file:
  3. path: /tmp/openshift
  4. state: directory
  5. owner: root
  6. mode: 700
  7. - name: Create service account configs
  8. template:
  9. src: serviceaccount.j2
  10. dest: "/tmp/openshift/{{ item }}-serviceaccount.yaml"
  11. with_items: accounts
  12. - name: Create {{ item }} service account
  13. command: >
  14. {{ openshift.common.client_binary }} create -f "/tmp/openshift/{{ item }}-serviceaccount.yaml"
  15. with_items: accounts
  16. register: _sa_result
  17. failed_when: "'serviceaccounts \"{{ item }}\" already exists' not in _sa_result.stderr and _sa_result.rc != 0"
  18. changed_when: "'serviceaccounts \"{{ item }}\" already exists' not in _sa_result.stderr and _sa_result.rc == 0"
  19. - name: Get current security context constraints
  20. shell: >
  21. {{ openshift.common.client_binary }} get scc privileged -o yaml
  22. --output-version=v1 > /tmp/openshift/scc.yaml
  23. changed_when: false
  24. - name: Add security context constraint for {{ item }}
  25. lineinfile:
  26. dest: /tmp/openshift/scc.yaml
  27. line: "- system:serviceaccount:default:{{ item }}"
  28. insertafter: "^users:$"
  29. with_items: accounts
  30. - name: Apply new scc rules for service accounts
  31. command: "{{ openshift.common.client_binary }} update -f /tmp/openshift/scc.yaml --api-version=v1"