-
Notifications
You must be signed in to change notification settings - Fork 40
/
prepare-ocp4-aws-config.yml
82 lines (79 loc) · 3 KB
/
prepare-ocp4-aws-config.yml
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
# Extra_vars for the running this playbook
# 1. cluster_name: Name of the cluster to be provisioned
# 2. aws_region: region on which the ocp_cluster needs to be deployed
# 3. ocp_install_directory:
# Directory in which the cluster config files are generated
# by default it is fetched from pipleline_repo_path
# 4. ocp_install_config_template: ocp_config file template path
# 5. pull_secret_file: path to file containing pull secret dictionary (required)
# 6. ssh_key_file: path to file containing ssh_key_file (required)
---
- name: "Prepare OCP 4.x configuration for installation on AWS"
hosts: localhost
become: false
gather_facts: false
pre_tasks:
# set the default variable using set_fact
- name: >
"Set default varibles such that they can
be overridden by extra-vars and
environment variables"
set_fact:
cluster_name: "{{ cluster_name | default('test-cluster') }}"
aws_region: "{{ aws_region | default('us-east-2') }}"
- name: "Set OCP install directory"
# Note: all the set_fact variables are
# fetched from extra-vars passed to playbook
# if the variables are not found they
# would be assuming the default variables
set_fact:
ocp_install_directory: >
"{{ ocp_install_directory |
default(playbook_dir) }}"
ocp_install_config_template: |
"{{ ocp_install_config_template |
default(playbook_dir+'/install-config.yaml.j2') }}"
tasks:
- name: "Ensure that the ocp install directory exists and is empty"
file:
path: "{{ ocp_install_directory }}/{{ cluster_name }}"
state: "{{ item }}"
mode: 0644
with_items:
- absent
- directory
- name: >
"Inject cluster name: {{ cluster_name }}
and region: {{ aws_region }} into
the install config"
template:
src: "{{ ocp_install_config_template }}"
dest: >
"{{ ocp_install_directory }}/{{
cluster_name }}/install-config.yaml"
mode: 0644
- name: Read pull_secret_file
shell: "cat {{ pull_secret_file }}"
register: pull_secret_contents
when: pull_secret_file is defined and ssh_key_file is defined
- name: Read ssh_key_file
shell: "cat {{ ssh_key_file }}"
register: ssh_key_file_contents
when: pull_secret_file is defined and ssh_key_file is defined
- name: "Prepare the dictionary"
set_fact:
secret_dict: >
"pullSecret: '{{ pull_secret_contents.stdout
}}'\nsshKey: '{{ ssh_key_file_contents.stdout }}'"
no_log: true
when: pull_secret_file is defined and ssh_key_file is defined
- name: "Inject secrets into the install-config"
blockinfile:
path: >
"{{ ocp_install_directory }}/{{
cluster_name }}/install-config.yaml"
block: "{{ secret_dict }}"
insertafter: EOF
marker: ""
no_log: true
when: pull_secret_file is defined and ssh_key_file is defined