Guillaume Coré
2018-12-04 031e351de62eeeaf7bc1aaa8439baecfc1402f1a
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
- name: Step 00xxxxx post software
  hosts: bastions
  become: yes
  gather_facts: False
  tasks:
  - debug:
      msg: "Post-Software Steps starting"
 
  - name: Set hostname fact
    set_fact:
      hostname: "{{ ansible_hostname}}.{{subdomain_base}}"
 
  - name: Set hostname
    hostname:
      name: "{{ hostname }}"
 
  - name: Make hostname permanent
    command: "echo {{ hostname }} > /etc/hostname"
 
  - name: Ensure software is installed
    yum:
      name: "{{ item }}"
      state: latest
    with_items:
    - git
    - vim
    - ansible
    - docker
 
  - name: Copy docker registries.conf file
    copy:
      src: ./files/registries.conf
      dest: /etc/containers/registries.conf
      mode: 0644
      owner: root
      group: root
 
  - name: Ensure /root/.docker directory exists
    file:
      path: /root/.docker
      state: directory
      mode: 775
      owner: root
      group: root
 
  - name: Copy docker config.conf file
    when: osrelease is version_compare('3.11', '>=')
    template:
      src: ./files/config.j2
      dest: /root/.docker/config.json
      mode: 0644
      owner: root
      group: root
 
  - name: Restart docker
    systemd:
      name: docker
      state: restarted
 
  - name: Set OpenShift root config directory
    set_fact:
      ocp_root: "/var/lib/openshift"
 
  - name: Ensure OpenShift config directory exists
    file:
      path: "{{ ocp_root }}"
      state: directory
      owner: root
      group: root
      mode: 0775
 
  - name: Ensure OpenShift config subdirectories exists for OCP 3.9
    file:
      path: "{{ item }}"
      state: directory
      owner: root
      group: root
      mode: 0775
    with_items:
      - "{{ ocp_root }}/config"
      - "{{ ocp_root }}/data"
      - "{{ ocp_root }}/pv"
      - "{{ ocp_root }}/volumes"
    when: osrelease is version_compare("3.10", "<")
 
  - name: Create oc_cluster system service
    template:
      src: ./files/oc-cluster.service.j2
      dest: "/usr/lib/systemd/system/oc-cluster.service"
 
  - name: Enable and start oc-cluster system service
    systemd:
      name: oc-cluster
      enabled: yes
      state: started
    register: r_systemd
    ignore_errors: yes
    tags: setup_cluster
 
  # there is a bug that happens sometimes (1/100),
  # the service is in fail state. Reboot fixes the issue.
  - name: Restart VM in case of Service Start failure
    when: r_systemd is failed
    tags: setup_cluster
    block:
      - name: Reboot VM
        command: shutdown -r +1
        async: 0
        poll: 0
        ignore_errors: yes
 
      - name: wait for linux host to be available (retry)
        wait_for_connection:
          delay: 90
          timeout: 200
 
      - ping:
        register: rping
        retries: 3
        delay: 10
        until: rping is succeeded
 
      - name: Retry to enable and start oc-cluster system service
        systemd:
          name: oc-cluster
          enabled: yes
          state: started
 
  - name: Wait for oc-cluster to be up and running
    tags: setup_cluster
    wait_for:
      host: "{{ hostname }}"
      port: 8443
      sleep: 2
 
  - name: Check if cluster is already set up
    tags: setup_cluster
    stat:
      path: /root/.setupcomplete
    register: occluster_setup
 
  - name: Setup and configure oc cluster
    tags: setup_cluster
    when: not occluster_setup.stat.exists
    block:
      - name: Login as system:admin
        shell: "oc login -u system:admin"
 
      - name: Deploy ocp-workloads for each user ID
        include_role:
          name: "{{ workload_loop_var }}"
        vars:
          guid: a1001
          ocp_user_needs_quota: false
          ocp_domain: "https://{{ hostname }}:8443"
          subdomain_base: "{{ ansible_hostname}}.{{subdomain_base}}"
          ocp_username: developer
          ACTION: create
          become_override: yes
        loop: "{{ student_workloads.split(',')|list }}"
        loop_control:
          loop_var: workload_loop_var
 
      - name: Touch setup file
        command: touch /root/.setupcomplete
 
- name: PostSoftware flight-check
  hosts: localhost
  connection: local
  gather_facts: false
  become: false
  tags:
  - post_flight_check
  tasks:
  - debug:
      msg: "Post-Software checks completed successfully"