main.yml 1.0 KB

1234567891011121314151617181920212223242526
  1. - name: Create service account configs
  2. template:
  3. src: serviceaccount.j2
  4. dest: "/tmp/{{ item }}-serviceaccount.yaml"
  5. with_items: accounts
  6. - name: Create {{ item }} service account
  7. command: >
  8. {{ openshift.common.client_binary }} create -f "/tmp/{{ item }}-serviceaccount.yaml"
  9. with_items: accounts
  10. register: _sa_result
  11. failed_when: "'serviceaccounts \"{{ item }}\" already exists' not in _sa_result.stderr and _sa_result.rc != 0"
  12. changed_when: "'serviceaccounts \"{{ item }}\" already exists' not in _sa_result.stderr and _sa_result.rc == 0"
  13. - name: Get current security context constraints
  14. shell: "{{ openshift.common.client_binary }} get scc privileged -o yaml > /tmp/scc.yaml"
  15. - name: Add security context constraint for {{ item }}
  16. lineinfile:
  17. dest: /tmp/scc.yaml
  18. line: "- system:serviceaccount:default:{{ item }}"
  19. insertafter: "^users:$"
  20. with_items: accounts
  21. - name: Apply new scc rules for service accounts
  22. command: "{{ openshift.common.client_binary }} update -f /tmp/scc.yaml"