Mario Vázquez
2019-07-30 1e2ca71eab2d1c2704086dabfb3dcf94f5543885
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
# Implement your Workload deployment tasks here
 
- name: Setting up workload for user
  debug:
    msg: "Setting up workload for user ocp_username = {{ ocp_username }}"
 
- name: Setting up custom facts
  set_fact:
    pacman_cluster1_route_hostname: "pacman.{{ cluster1_wildcard_domain }}"
    pacman_cluster2_route_hostname: "pacman.{{ cluster2_wildcard_domain }}"
    pacman_cluster3_route_hostname: "pacman.{{ cluster3_wildcard_domain }}"
 
- name: Ensure OpenShift Objects for KubeFed are Created
  k8s:
    state: present
    merge_type:
    - strategic-merge
    - merge
    definition: "{{ lookup('template', item ) | from_yaml }}"
  loop:
    - ./templates/kubefed_project.j2
    - ./templates/catalog_source_config.j2
    - ./templates/operator_group.j2
    - ./templates/subscription.j2
 
- name: Wait until InstallPlan is Created
  shell: oc get installplan -o name -n "{{ _kubefed_project }}" | awk -F "/" '{print $2}'
  register: install_plan
  retries: 30
  delay: 10
  until: install_plan.stdout != ""
 
- name: Ensure InstallPlan is Approved
  command: oc patch installplan "{{ install_plan.stdout }}" --type merge -p '{"spec":{"approved":true}}' -n "{{ _kubefed_project }}"
 
- name: Wait until CSV is Installed
  command: oc get csv "{{ _kubefed_subscription_csv }}" -o jsonpath='{.status.phase}' -n "{{ _kubefed_project }}"
  register: csv
  retries: 30
  delay: 10
  until: csv.stdout == "Succeeded"
 
- name: Get KubeFed Operator Deployment Desired Replicas
  command: oc get deployment "{{ _kubefed_operator_deployment }}" -o jsonpath='{.status.replicas}' -n "{{ _kubefed_project }}"
  register: kubefed_operator_desired_replicas
  retries: 30
  delay: 10
  until: kubefed_operator_desired_replicas.stdout != ""
 
- name: Wait until KubeFed Operator Deployment is Ready
  command: oc get deployment "{{ _kubefed_operator_deployment }}" -o jsonpath='{.status.readyReplicas}' -n "{{ _kubefed_project }}" 
  register: kubefed_operator_ready_replicas
  retries: 30
  delay: 10
  until: kubefed_operator_ready_replicas.stdout == kubefed_operator_desired_replicas.stdout
 
- name: Ensure KubeFed Resource is Created
  k8s:
    state: present
    merge_type:
    - strategic-merge
    - merge
    definition: "{{ lookup('template', item ) | from_yaml }}"
  loop:
    - ./templates/kubefed.j2
 
- name: Get KubeFed Controller Deployment Desired Replicas
  command: oc get deployment "{{ _kubefed_controller_deployment }}" -o jsonpath='{.status.replicas}' -n "{{ _kubefed_project }}"
  register: kubefed_controller_desired_replicas
  retries: 30
  delay: 10
  until: kubefed_controller_desired_replicas.stdout != ""
 
- name: Wait until KubeFed Controller Deployment is Ready
  command: oc get deployment "{{ _kubefed_controller_deployment }}" -o jsonpath='{.status.readyReplicas}' -n "{{ _kubefed_project }}"
  register: kubefed_controller_ready_replicas
  retries: 30
  delay: 10
  until: kubefed_controller_ready_replicas.stdout == kubefed_controller_desired_replicas.stdout
 
- name: Ensure Pacman LB Route is Created
  k8s:
    state: present
    merge_type:
    - strategic-merge
    - merge
    definition: "{{ lookup('template', item ) | from_yaml }}"
  loop:
    - ./templates/haproxy_project.j2
    - ./templates/haproxy_route.j2
 
- name: Get HAProxy Route
  command: oc get route haproxy-lb -o jsonpath='{.status.ingress[*].host}' -n "{{ _haproxy_project }}"
  register: haproxy_route_hostname
  retries: 30
  delay: 10
  until: haproxy_route_hostname.stdout != ""
 
- name: Set Pacman LB Fact
  set_fact:
    pacman_lb_hostname: "{{ haproxy_route_hostname.stdout }}"
 
- name: Ensure OpenShift Objects for HAProxy are Created
  k8s:
    state: present
    merge_type:
    - strategic-merge
    - merge
    definition: "{{ lookup('template', item ) | from_yaml }}"
  loop:
    - ./templates/haproxy_configmap.j2
    - ./templates/haproxy_service.j2
    - ./templates/haproxy_deployment.j2
 
- name: Ensure kubefedctl Tool is Downloaded
  unarchive: 
    src: "https://github.com/kubernetes-sigs/kubefed/releases/download/v{{ _kubefedctl_release }}/kubefedctl-{{ _kubefedctl_release }}-linux-amd64.tgz"
    dest: /usr/local/bin
    remote_src: yes
    mode: 0755
  become: true
 
- name: Ensure cfssl Tool is Downloaded
  get_url:
    url: "https://pkg.cfssl.org/{{ _cfssl_release }}/cfssl_linux-amd64"
    dest: /usr/local/bin/cfssl
    mode: 0755
  become: true
 
- name: Ensure cfssljson Tool is Downloaded
  get_url:
    url: "https://pkg.cfssl.org/{{ _cfssl_release }}/cfssljson_linux-amd64"
    dest: /usr/local/bin/cfssljson
    mode: 0755
  become: true
 
# The value of pacman_lb_hostname should be presented to the student somewhere as
# it will be the route they use for connecting to pacman application
- debug:
    var: pacman_lb_hostname
 
# Leave this as the last task in the playbook.
- name: workload tasks complete
  debug:
    msg: "Workload Tasks completed successfully."
  when: not silent|bool