Guillaume Coré
2019-10-08 96df46441788cad3472258535bd5048f532eda98
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
# Implement your Post Workload deployment tasks here
- name: Get current user
  command: oc whoami
  register: current_user
 
- when:
    - ocp_username is defined
    - ocp_username != current_user.stdout
  block:
    - name: Annotate the completed project as requested by user (ocp_projects)
      command: >-
        oc annotate namespace {{_ocp_project}}
        openshift.io/requester={{ocp_username}} --overwrite
      loop: "{{ ocp_projects | default([]) }}"
      loop_control:
        loop_var: _ocp_project
 
    - name: Annotate the completed project as requested by user (target_namespaces)
      command: >-
        oc annotate namespace {{_ocp_project}}
        openshift.io/requester={{ocp_username}} --overwrite
      loop: "{{ target_namespaces | default([]) }}"
      loop_control:
        loop_var: _ocp_project
 
    - name: Annotate the completed project as requested by user
      when:
        - ocp_project is defined
        - ocp_project != ''
      command: >-
        oc annotate namespace {{ocp_project}}
        openshift.io/requester={{ocp_username}} --overwrite
    # Leave this as the last task in the playbook.
    - name: post_workload tasks complete
      debug:
        msg: "Post-Workload Tasks completed successfully."
      when: not silent|bool
  rescue:
    - debug:
        msg: >-
          ocp_username is different from the user you're connected to.
          The workload tries to change the annotation openshift.io/request,
          but failed.