-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocplabs-ocp-nodes-setup.yaml
224 lines (224 loc) · 8.43 KB
/
ocplabs-ocp-nodes-setup.yaml
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
- hosts: masters:nodes
gather_facts: true
vars:
net_interfaces: [ 'enp1s0' ]
tasks:
- name: configure_network_if | Configure Network interfaces
template: owner=root group=root mode=644
src=ocplabs-ifcfg-interface-template
dest="/etc/sysconfig/network-scripts/ifcfg-{{ item }}"
with_items: "{{ net_interfaces }}"
- name: check_ostree | Check if system is Atomic Host
stat: path=/etc/ostree
register: check_ostree
- name: check_parted | Check if system has parted installed
stat: path=/usr/sbin/parted
register: check_parted
- name: setup_nodes | Register host and subscribe
redhat_subscription:
state: present
username: "{{rhn_user}}"
password: "{{rhn_password}}"
pool: "{{rhn_pool_id}}"
ignore_errors: yes
- name: setup_nodes | Disable all repos
shell: subscription-manager repos --disable="*"
when: check_ostree.stat.exists == false or check_parted.stat.exists == false
- name: setup_nodes | Enable OCP and RHSCL repos (needed for Fedora)
shell: subscription-manager repos --enable="rhel-7-server-rpms" --enable="rhel-7-server-extras-rpms" --enable="rhel-7-server-ose-3.11-rpms" --enable="rhel-7-fast-datapath-rpms" --enable="rhel-server-rhscl-7-rpms" --enable="rh-gluster-3-for-rhel-7-server-rpms"
when: check_ostree.stat.exists == false or check_parted.stat.exists == false
- name: setup_nodes| Install deltarpm
yum:
name: deltarpm
when: check_ostree.stat.exists == false
- name: setup_nodes | Install rpms
yum:
name="{{ item }}"
state=installed
with_items:
- wget
- git
- net-tools
- bind-utils
- iptables-services
- bridge-utils
- bash-completion
- kexec-tools
- sos
- psacct
- python-virtualenv
- gcc
- atomic-openshift-utils
- atomic-openshift-excluder
- atomic-openshift-clients
- atomic-openshift
- rh-python35
- cns-deploy
- heketi-client
when: check_ostree.stat.exists == false
- name: setup_nodes | Install parted
shell: atomic host install {{ item }}
with_items:
- parted
ignore_errors: yes
when: check_ostree.stat.exists == true and check_parted.stat.exists == false
- name: configure_hosts | Configure /etc/hosts
lineinfile: dest=/etc/hosts line="{{ hostvars[item]['ansible_host'] }} {{ hostvars[item]['inventory_hostname'] }}"
with_items: "{{groups.all}}"
- name: configure_hosts | Configure /etc/hosts for Docker registries (point to Nexus)
lineinfile: dest=/etc/hosts line="192.168.1.106 {{item}}"
with_items:
- registry.access.redhat.com
- registry.redhat.io
- name: start_lvm_socket | Start LVM Socket
systemd:
name: lvm2-lvmetad.socket
enabled: yes
daemon_reload: yes
state: started
- name: start_lvm_service | Start LVM Service
systemd:
name: lvm2-lvmetad.service
enabled: yes
daemon_reload: yes
state: started
- name: configure_docker_storage | Setup Docker partition
parted:
device: /dev/sda
number: 4
label: gpt
flags: [ lvm ]
state: present
part_start: "{{ ((ansible_devices.sda.partitions.sda3.start | int ) + (ansible_devices.sda.partitions.sda3.sectors | int )) | round | int }}s"
part_end: 100%
- name: configure_docker_storage | Setup Docker volume group
lvg:
pvs: /dev/sda4
vg: docker-vg
state: present
register: docker_vg
- name: configure_docker_storage | Stop Docker
systemd:
name: docker
state: stopped
when: docker_vg.changed
- name: configure_docker_storage | Remove previous Docker lib directory
file:
path: /var/lib/docker
state: absent
when: docker_vg.changed
- name: configure_docker_storage | Configure Docker storage (set volume group)
lineinfile: dest=/etc/sysconfig/docker-storage-setup line="VG=docker-vg"
- name: configure_docker_storage | Configure Docker storage (set lvm thin pool)
lineinfile: dest=/etc/sysconfig/docker-storage-setup line="SETUP_LVM_THIN_POOL=yes"
- name: configure_docker_storage | Configure Docker storage (remove container thinpool)
lineinfile: dest=/etc/sysconfig/docker-storage-setup regexp="CONTAINER_THINPOOL=.*" state=absent
- name: configure_docker_storage | Configure Docker storage (remove DOCKER_STORAGE_OPTIONS)
lineinfile: dest=/etc/sysconfig/docker-storage regexp="DOCKER_STORAGE_OPTIONS=.*" state=absent
- name: configure_docker_storage | Delete previous Docker storage volume
lvol:
vg: docker-vg
lv: docker-pool
state: absent
force: yes
when: docker_vg.changed
- name: configure_docker_storage | Setup Docker storage
shell: docker-storage-setup
when: docker_vg.changed
- name: configure_docker_storage | Extend Docker storage volume
lvol:
vg: docker-vg
lv: docker-pool
size: +100%FREE
when: docker_vg.changed
- name: configure_docker | Configure Docker
lineinfile: dest=/etc/sysconfig/docker
regexp="^OPTIONS=.*"
line="OPTIONS='--signature-verification=false --selinux-enabled --log-driver=journald --insecure-registry 172.30.0.0/16 --insecure-registry 192.168.1.106'"
state=present
when: docker_vg.changed
- name: configure_docker | Configure Docker
lineinfile: dest=/etc/sysconfig/docker
regexp="^ADD_REGISTRY=.*"
line="ADD_REGISTRY='--add-registry 192.168.1.106'"
state=present
when: docker_vg.changed
- name: configure_docker | Configure Docker registries
template:
src: ocplabs-containers-registries.conf
dest: /etc/containers/registries.conf
owner: root
group: root
mode: 0640
when: check_ostree.stat.exists == true
- name: configure_docker | Start Docker
systemd:
name: docker
state: started
- name: setup_cockpit | Setup Cockpit Service
copy:
src: ocplabs-cockpitws.service
dest: /etc/systemd/system/cockpitws.service
owner: root
group: root
mode: 0640
when: check_ostree.stat.exists == true
- name: setup_cockpit | Pull Cockpit Container
shell: docker pull rhel7/cockpit-ws
when: check_ostree.stat.exists == true
- name: setup_cockpit | Setup Cockpit Container
shell: atomic install rhel7/cockpit-ws
when: check_ostree.stat.exists == true
- name: setup_cockpit | Start Cockpit Service
systemd:
name: cockpitws.service
enabled: yes
daemon_reload: yes
state: started
when: check_ostree.stat.exists == true
- name: setup_cockpit | Setup firewall for Cockpit
iptables:
chain: INPUT
protocol: tcp
destination_port: 9090
jump: ACCEPT
when: check_ostree.stat.exists == true
- name: setup_cockpit | Save firewall settings for Cockpit
shell: iptables-save > /etc/sysconfig/iptables
- hosts: masters
tasks:
- name: check_ostree | Check if system is Atomic Host
stat: path=/etc/ostree
register: check_ostree
- name: docker_check_node_images | Check Docker Images for Masters
shell: docker images '{{item}}' | grep -e '.*{{item.split(":")[0]}}.*{{item.split(":")[1]}}.*' | awk '{}END{ if (!NR) print "{{item}}"}'
register: docker_images_missing
with_items:
- openshift3/ose-node:v3.11
- openshift3/ose-pod:v3.11
- openshift3/ose:v3.11
- openshift3/openvswitch:latest
- rhel7/etcd:latest
when: check_ostree.stat.exists == true
- name: docker_pull_master | Pull Docker Images for Masters
shell: docker pull {{item}}
with_items: "{{ docker_images_missing.results|map(attribute='stdout_lines')|list }}"
when: "check_ostree.stat.exists and docker_images_missing.results is defined"
- hosts: nodes
tasks:
- name: check_ostree | Check if system is Atomic Host
stat: path=/etc/ostree
register: check_ostree
- name: docker_check_node_images | Check Docker Images for Nodes
shell: docker images '{{item}}' | grep -e '.*{{item.split(":")[0]}}.*{{item.split(":")[1]}}.*' | awk '{}END{ if (!NR) print "{{item}}"}'
register: docker_images_missing
with_items:
- openshift3/ose-node:v3.11
- openshift3/ose-pod:v3.11
- openshift3/ose:v3.11
- openshift3/openvswitch:latest
when: check_ostree.stat.exists == true
- name: docker_pull_nodes | Pull Docker Images for Nodes
shell: docker pull {{item}}
with_items: "{{ docker_images_missing.results|map(attribute='stdout_lines')|list }}"
when: "check_ostree.stat.exists and docker_images_missing.results is defined"