summaryrefslogtreecommitdiffstats
path: root/roles/openshift_examples/tasks/main.yml
blob: 3563174314a1114ef0e9c33c093305e8a3d24598 (plain)
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
---
######################################################################
# Copying Examples
#
# We used to use the copy module to transfer the openshift examples to
# the remote. Then it started taking more than a minute to transfer
# the files. As noted in the module:
#
#   "The 'copy' module recursively copy facility does not scale to
#   lots (>hundreds) of files."
#
# The `synchronize` module is suggested as an alternative, we can't
# use it either due to changes introduced in Ansible 2.x.
- name: Create local temp dir for OpenShift examples copy
  local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  become: False
  register: copy_examples_mktemp
  run_once: True

- name: Create tar of OpenShift examples
  local_action: command tar -C "{{ role_path }}/files/examples/{{ content_version }}/" -cvf "{{ copy_examples_mktemp.stdout }}/openshift-examples.tar" .
  args:
    # Disables the following warning:
    # Consider using unarchive module rather than running tar
    warn: no
  become: False
  register: copy_examples_tar

- name: Create the remote OpenShift examples directory
  file:
    dest: "{{ examples_base }}"
    state: directory
    mode: 0755

- name: Unarchive the OpenShift examples on the remote
  unarchive:
    src: "{{ copy_examples_mktemp.stdout }}/openshift-examples.tar"
    dest: "{{ examples_base }}/"

- name: Cleanup the OpenShift Examples temp dir
  become: False
  local_action: file dest="{{ copy_examples_mktemp.stdout }}" state=absent

# Done copying examples
######################################################################
# Begin image streams

- name: Modify registry paths if registry_url is not registry.access.redhat.com
  shell: >
    find {{ examples_base }} -type f | xargs -n 1 sed -i 's|registry.access.redhat.com|{{ registry_host | quote }}|g'
  when: registry_host != '' and openshift_examples_modify_imagestreams | default(False) | bool

# RHEL and Centos image streams are mutually exclusive
- name: Import RHEL streams
  command: >
    {{ openshift.common.client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ item }}
  when: openshift_examples_load_rhel | bool
  with_items:
    - "{{ rhel_image_streams }}"
  register: oex_import_rhel_streams
  failed_when: "'already exists' not in oex_import_rhel_streams.stderr and oex_import_rhel_streams.rc != 0"
  changed_when: false

- name: Import Centos Image streams
  command: >
    {{ openshift.common.client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ item }}
  when: openshift_examples_load_centos | bool
  with_items:
    - "{{ centos_image_streams }}"
  register: oex_import_centos_streams
  failed_when: "'already exists' not in oex_import_centos_streams.stderr and oex_import_centos_streams.rc != 0"
  changed_when: false

- name: Import db templates
  command: >
    {{ openshift.common.client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ db_templates_base }}
  when: openshift_examples_load_db_templates | bool
  register: oex_import_db_templates
  failed_when: "'already exists' not in oex_import_db_templates.stderr and oex_import_db_templates.rc != 0"
  changed_when: false

- name: Remove defunct quickstart template files
  file:
    path: "{{ item }}"
    state: absent
  with_items:
    - "{{ quickstarts_base }}/nodejs.json"
    - "{{ quickstarts_base }}/cakephp.json"
    - "{{ quickstarts_base }}/dancer.json"
    - "{{ quickstarts_base }}/django.json"

- name: Remove defunct quickstart templates from openshift namespace
  command: "{{ openshift.common.client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift delete templates/{{ item }}"
  with_items:
    - nodejs-example
    - cakephp-example
    - dancer-example
    - django-example
  register: oex_delete_defunct_quickstart_templates
  failed_when: "'not found' not in oex_delete_defunct_quickstart_templates.stderr and oex_delete_defunct_quickstart_templates.rc != 0"
  changed_when: false

- name: Import quickstart-templates
  command: >
    {{ openshift.common.client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ quickstarts_base }}
  when: openshift_examples_load_quickstarts | bool
  register: oex_import_quickstarts
  failed_when: "'already exists' not in oex_import_quickstarts.stderr and oex_import_quickstarts.rc != 0"
  changed_when: false

- name: Remove old xPaas template files
  file:
    path: "{{ item }}"
    state: absent
  with_items:
    - "{{ xpaas_templates_base }}/sso70-basic.json"

- name: Remove old xPaas templates from openshift namespace
  command: "{{ openshift.common.client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift delete templates/{{ item }}"
  with_items:
    - sso70-basic
  register: oex_delete_old_xpaas_templates
  failed_when: "'not found' not in oex_delete_old_xpaas_templates.stderr and oex_delete_old_xpaas_templates.rc != 0"
  changed_when: false

- name: Import xPaas image streams
  command: >
    {{ openshift.common.client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ xpaas_image_streams }}
  when: openshift_examples_load_xpaas | bool
  register: oex_import_xpaas_streams
  failed_when: "'already exists' not in oex_import_xpaas_streams.stderr and oex_import_xpaas_streams.rc != 0"
  changed_when: false

- name: Import xPaas templates
  command: >
    {{ openshift.common.client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ xpaas_templates_base }}
  when: openshift_examples_load_xpaas | bool
  register: oex_import_xpaas_templates
  failed_when: "'already exists' not in oex_import_xpaas_templates.stderr and oex_import_xpaas_templates.rc != 0"
  changed_when: false