summaryrefslogtreecommitdiffstats
path: root/playbooks/groups/osbs-cluster.yml
blob: 844c8514d170c3fad2b1b9b2841326fbb6882d47 (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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# create an osbs server
- import_playbook:  "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=osbs-control"
- import_playbook:  "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=osbs-control-stg"
- import_playbook:  "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=osbs-nodes:osbs-masters"
- import_playbook:  "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=osbs-nodes-stg:osbs-masters-stg"
- import_playbook:  "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=osbs-aarch64-masters-stg"
- import_playbook:  "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=osbs-aarch64-masters"

- name: make the box be real
  hosts: osbs-control:osbs-masters:osbs-nodes:osbs-control-stg:osbs-masters-stg:osbs-nodes-stg:osbs-aarch64-masters-stg:osbs-aarch64-masters
  user: root
  gather_facts: True

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"

  roles:
    - base
    - rkhunter
    - nagios_client
    - hosts
    - fas_client
    - sudo
    - collectd/base
    - rsyncd

  tasks:
    - import_tasks: "{{ tasks_path }}/2fa_client.yml"
    - import_tasks: "{{ tasks_path }}/motd.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: OSBS control hosts pre-req setup
  hosts: osbs-control:osbs-control-stg
  tags:
    - osbs-cluster-prereq
  user: root
  gather_facts: True

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
    - name: deploy private key to control hosts
      copy:
        src: "{{private}}/files/osbs/{{env}}/control_key"
        dest: "/root/.ssh/id_rsa"
        owner: root
        mode: 0600

    - name: set ansible to use pipelining
      ini_file:
        dest: /etc/ansible/ansible.cfg
        section: ssh_connection
        option: pipelining
        value: "True"

- name: Setup cluster masters pre-reqs
  hosts: osbs-masters-stg:osbs-masters:osbs-aarch64-masters-stg:osbs-aarch64-masters
  tags:
    - osbs-cluster-prereq
  user: root
  gather_facts: True

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
    - name: ensure origin conf dir exists
      file:
        path: "/etc/origin"
        state: "directory"

    - name: create cert dir for openshift public facing REST API SSL
      file:
        path: "/etc/origin/master/named_certificates"
        state: "directory"

    - name: install cert for openshift public facing REST API SSL
      copy:
        src: "{{private}}/files/osbs/{{env}}/osbs-internal.pem"
        dest: "/etc/origin/master/named_certificates/{{osbs_url}}.pem"

    - name: install key for openshift public facing REST API SSL
      copy:
        src: "{{private}}/files/osbs/{{env}}/osbs-internal.key"
        dest: "/etc/origin/master/named_certificates/{{osbs_url}}.key"

    - name: place htpasswd file
      copy:
        src: "{{private}}/files/httpd/osbs-{{env}}.htpasswd"
        dest: /etc/origin/htpasswd


- name: Setup cluster hosts pre-reqs
  hosts: osbs-masters-stg:osbs-nodes-stg:osbs-masters:osbs-nodes:osbs-aarch64-masters-stg:osbs-aarch64-masters
  tags:
    - osbs-cluster-prereq
  user: root
  gather_facts: True

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  handlers:
    - name: restart NetworkManager
      service:
        name: NetworkManager
        state: restarted

  tasks:
    - name: Install necessary packages that openshift-ansible needs
      package: name="{{ item }}" state=installed
      with_items:
        - tar
        - rsync
        - dbus-python
        - NetworkManager
        - libselinux-python
        - python3-PyYAML

    - name: Deploy controller public ssh keys to osbs cluster hosts
      authorized_key:
        user: root
        key: "{{ lookup('file', '{{private}}/files/osbs/{{env}}/control_key.pub') }}"

    # This is required for OpenShift built-in SkyDNS inside the overlay network
    # of the cluster
    - name: ensure NM_CONTROLLED is set to "yes" for osbs cluster
      lineinfile:
        dest: "/etc/sysconfig/network-scripts/ifcfg-eth0"
        line: "NM_CONTROLLED=yes"
      notify:
        - restart NetworkManager

    # This is required for OpenShift built-in SkyDNS inside the overlay network
    # of the cluster
    - name: ensure NetworkManager is enabled and started
      service:
        name: NetworkManager
        state: started
        enabled: yes

    - name: cron entry to clean up docker storage
      copy:
        src: "{{files}}/osbs/cleanup-docker-storage"
        dest: "/etc/cron.d/cleanup-docker-storage"

    - name: copy docker-storage-setup config
      copy:
        src: "{{files}}/osbs/docker-storage-setup"
        dest:  "/etc/sysconfig/docker-storage-setup"

- name: Deploy kerberose keytab to cluster hosts
  hosts: osbs-masters-stg:osbs-nodes-stg:osbs-masters:osbs-nodes:osbs-aarch64-masters-stg:osbs-aarch64-masters
  tags:
    - osbs-cluster-prereq
  user: root
  gather_facts: True

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: keytab/service
    owner_user: root
    owner_group: root
    service: osbs
    host: "osbs.fedoraproject.org"
    when: env == "production"
  - role: keytab/service
    owner_user: root
    owner_group: root
    service: osbs
    host: "osbs.stg.fedoraproject.org"
    when: env == "staging"

- name: Deploy OpenShift Cluster x86_64
  hosts: osbs-control:osbs-control-stg
  tags:
    - osbs-deploy-openshift
    - osbs-x86-deploy-openshift
  user: root
  gather_facts: True

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
    - role: ansible-ansible-openshift-ansible
      cluster_inventory_filename: "{{ inventory_filename }}"
      openshift_htpasswd_file: "/etc/origin/htpasswd"
      openshift_master_public_api_url: "https://{{ osbs_url }}:8443"
      openshift_release: "v3.9.0"
      openshift_ansible_path: "/root/openshift-ansible"
      openshift_ansible_pre_playbook: "playbooks/prerequisites.yml"
      openshift_ansible_playbook: "playbooks/deploy_cluster.yml"
      openshift_ansible_version: "openshift-ansible-3.9.37-1"
      openshift_ansible_ssh_user: root
      openshift_ansible_install_examples: false
      openshift_ansible_containerized_deploy: false
      openshift_cluster_masters_group: "{{ cluster_masters_group }}"
      openshift_cluster_nodes_group: "{{ cluster_nodes_group }}"
      openshift_cluster_infra_group: "{{ cluster_infra_group }}"
      openshift_auth_profile: "osbs"
      openshift_cluster_url: "https://{{osbs_url}}"
      openshift_master_ha: false
      openshift_debug_level: 2
      openshift_shared_infra: true
      openshift_deployment_type: "origin"
      openshift_ansible_python_interpreter: "/usr/bin/python3"
      openshift_ansible_use_crio: false
      openshift_ansible_crio_only: false
      tags: ['openshift-cluster-x86','ansible-ansible-openshift-ansible']

- name: Deploy OpenShift Cluster aarch64
  hosts: osbs-control:osbs-control-stg
  tags:
    - osbs-deploy-openshift
    - osbs-aarch-deploy-openshift
  user: root
  gather_facts: True

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
    - role: ansible-ansible-openshift-ansible
      cluster_inventory_filename: "{{ inventory_filename }}"
      openshift_htpasswd_file: "/etc/origin/htpasswd"
      openshift_master_public_api_url: "https://{{ osbs_url }}:8443"
      openshift_release: "v3.9.0"
      openshift_ansible_path: "/root/openshift-ansible"
      openshift_ansible_pre_playbook: "playbooks/prerequisites.yml"
      openshift_ansible_playbook: "playbooks/deploy_cluster.yml"
      openshift_ansible_version: "osbs-aarch64-fedora"
      openshift_ansible_ssh_user: root
      openshift_ansible_install_examples: false
      openshift_ansible_containerized_deploy: false
      openshift_cluster_masters_group: "{{ aarch_masters_group }}"
      openshift_cluster_nodes_group: "{{ aarch_nodes_group }}"
      openshift_cluster_infra_group: "{{ aarch_infra_group }}"
      openshift_auth_profile: "osbs"
      openshift_cluster_url: "https://{{osbs_url}}"
      openshift_master_ha: false
      openshift_debug_level: 2
      openshift_shared_infra: true
      openshift_deployment_type: "origin"
      openshift_ansible_python_interpreter: "/usr/bin/python3"
      openshift_ansible_use_crio: false
      openshift_ansible_crio_only: false
      tags: ['openshift-cluster-aarch','ansible-ansible-openshift-ansible']

- name: Setup OSBS requirements for OpenShift cluster hosts
  hosts: osbs-masters-stg:osbs-nodes-stg:osbs-masters:osbs-nodes
  tags:
    - osbs-cluster-req
  user: root
  gather_facts: True

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
    - name: Ensures /etc/dnsmasq.d/ dir exists
      file: path="/etc/dnsmasq.d/" state=directory
    - name: install fedora dnsmasq specific config
      copy:
        src: "{{files}}/osbs/fedora-dnsmasq.conf.{{env}}"
        dest: "/etc/dnsmasq.d/fedora-dns.conf"

- name: Create worker namespace
  hosts: osbs-masters-stg[0]:osbs-masters[0]:osbs-aarch64-masters-stg[0]:osbs-aarch64-masters[0]
  tags:
    - osbs-worker-namespace
  user: root
  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  vars:
    osbs_kubeconfig_path: /etc/origin/master/admin.kubeconfig
    osbs_environment:
      KUBECONFIG: "{{ osbs_kubeconfig_path }}"

  roles:
    - role: osbs-namespace
      osbs_namespace: "{{ osbs_worker_namespace }}"
      osbs_service_accounts: "{{ osbs_worker_service_accounts }}"
      osbs_nodeselector: "{{ osbs_worker_default_nodeselector|default('') }}"
      osbs_sources_command: "{{ osbs_conf_sources_command }}"

- name: setup ODCS secret in worker namespace
  hosts: osbs-masters-stg[0]:osbs-masters[0]:osbs-aarch64-masters-stg[0]:osbs-aarch64-masters[0]
  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  roles:
  - role: osbs-secret
    osbs_namespace: "{{ osbs_worker_namespace }}"
    osbs_secret_name: odcs-oidc-secret
    osbs_secret_files:
    - source: "{{ private }}/files/osbs/{{ env }}/odcs-oidc-token"
      dest: token
  tags:
    - osbs-worker-namespace

- name: Create orchestrator namespace
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  roles:
  - role: osbs-namespace
    osbs_orchestrator: true
    osbs_worker_clusters: "{{ osbs_conf_worker_clusters }}"
    osbs_cpu_limitrange: "{{ osbs_orchestrator_cpu_limitrange }}"
    osbs_nodeselector: "{{ osbs_orchestrator_default_nodeselector|default('') }}"
    osbs_sources_command: "{{ osbs_conf_sources_command }}"
    osbs_readwrite_users: "{{ osbs_conf_readwrite_users }}"
    osbs_service_accounts: "{{ osbs_conf_service_accounts }}"
    koji_use_kerberos: true
    koji_kerberos_keytab: "FILE:/etc/krb5.osbs_{{ osbs_url }}.keytab"
    koji_kerberos_principal: "osbs/{{osbs_url}}@{{ ipa_realm }}"
  tags:
    - osbs-orchestrator-namespace


- name: Add the orchestrator labels to the nodes
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  tags:
    - osbs-labels-nodes
  tasks:
    - name: Add the orchestrator labels to the nodes
      command: "oc -n {{ osbs_namespace }} label nodes {{ item }} orchestrator=true --overwrite"
      loop: "{{ groups['osbs-nodes-stg'] }}"
      when: env == "staging"

    - name: Add the orchestrator labels to the nodes
      command: "oc -n {{ osbs_namespace }} label nodes {{ item }} orchestrator=true --overwrite"
      loop: "{{ groups['osbs-nodes'] }}"
      when: env == "production"

- name: Add the worker labels to the nodes x86_64
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  tags:
    - osbs-labels-nodes
  tasks:
    - name: Add the worker label
      command: "oc -n {{ osbs_worker_namespace }} label nodes {{ item }} worker=true --overwrite"
      loop: "{{ groups['osbs-nodes-stg'] }}"
      when: env == "staging"
    - name: Add the worker label
      command: "oc -n {{ osbs_worker_namespace }} label nodes {{ item }} worker=true --overwrite"
      loop: "{{ groups['osbs-nodes'] }}"
      when: env == "production"

- name: Add the worker labels to the nodes aarch64
  hosts: osbs-aarch64-masters-stg[0]:osbs-aarch64-masters[0]
  tags:
    - osbs-labels-nodes
  tasks:
    - name: Add the worker label
      command: "oc -n {{ osbs_worker_namespace }} label nodes {{ item }} worker=true --overwrite"
      loop: "{{ groups['osbs-aarch64-nodes-stg'] }}"
      when: env == "staging"
    - name: Add the worker label
      command: "oc -n {{ osbs_worker_namespace }} label nodes {{ item }} worker=true --overwrite"
      loop: "{{ groups['osbs-aarch64-nodes'] }}"
      when: env == "production"

- name: setup reactor config secret in orchestrator namespace
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  roles:
  - role: osbs-secret
    osbs_secret_name: reactor-config-secret
    osbs_secret_files:
    - source: "/tmp/{{ osbs_namespace }}-reactor-config-secret.yml"
      dest: config.yaml
  tags:
    - osbs-orchestrator-namespace

- name: setup ODCS secret in orchestrator namespace
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  roles:
  - role: osbs-secret
    osbs_secret_name: odcs-oidc-secret
    osbs_secret_files:
    - source: "{{ private }}/files/osbs/{{ env }}/odcs-oidc-token"
      dest: token
  tags:
    - osbs-orchestrator-namespace


- name: setup client config secret in orchestrator namespace
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  roles:
  - role: osbs-secret
    osbs_secret_name: client-config-secret
    osbs_secret_files:
    - source: "/tmp/{{ osbs_namespace }}-client-config-secret.conf"
      dest: osbs.conf
  tags:
    - osbs-orchestrator-namespace

- name: Save orchestrator token x86_64
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  tasks:
    - name: get orchestrator service account token
      command: "oc -n {{ osbs_worker_namespace }} sa get-token orchestrator"
      register: orchestator_token_x86_64
    - name: save the token locally
      local_action: >
        copy
        content="{{ orchestator_token_x86_64.stdout }}"
        dest=/tmp/.orchestator-token-x86_64
        mode=0400
  tags:
    - osbs-orchestrator-namespace

- name: setup orchestrator token for x86_64-osbs
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  roles:
  - role: osbs-secret
    osbs_secret_name: x86-64-orchestrator
    osbs_secret_files:
    - source: "/tmp/.orchestator-token-x86_64"
      dest: token

  post_tasks:
  - name: Delete the temporary secret file
    local_action: >
      file
      state=absent
      path="/tmp/.orchestator-token-x86_64"
  tags:
    - osbs-orchestrator-namespace

- name: Save orchestrator token aarch64
  hosts: osbs-aarch64-masters-stg[0]:osbs-aarch64-masters[0]
  tasks:
    - name: get orchestrator service account token
      command: "oc -n {{ osbs_worker_namespace }} sa get-token orchestrator"
      register: orchestator_token_aarch64
    - name: save the token locally
      local_action: >
        copy
        content="{{ orchestator_token_aarch64.stdout }}"
        dest=/tmp/.orchestator-token-aarch64
        mode=0400
  tags:
    - osbs-orchestrator-namespace

- name: setup orchestrator token for aarch64-osbs
  hosts: osbs-masters-stg[0]
  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  roles:
  - role: osbs-secret
    osbs_secret_name: aarch64-orchestrator
    osbs_secret_files:
    - source: "/tmp/.orchestator-token-aarch64"
      dest: token

  post_tasks:
  - name: Delete the temporary secret file
    local_action: >
      file
      state=absent
      path="/tmp/.orchestator-token-aarch64"

  tags:
    - osbs-orchestrator-namespace

- name: Add dockercfg secret to allow registry push orchestrator
  hosts: osbs-masters-stg[0]:osbs-masters[0]
  tags:
    - osbs-dockercfg-secret
  user: root

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
    - name: Create the username:password string needed by the template
      set_fact:
        auth_info_prod: "{{candidate_registry_osbs_prod_username}}:{{candidate_registry_osbs_prod_password}}"
        auth_info_stg: "{{candidate_registry_osbs_stg_username}}:{{candidate_registry_osbs_stg_password}}"

    - name: Create the dockercfg secret file
      local_action: >
        template
        src="{{ files }}/osbs/dockercfg-{{env}}-secret.j2"
        dest="/tmp/.dockercfg"
        mode=0400

  roles:
  - role: osbs-secret
    osbs_secret_name: "v2-registry-dockercfg"
    osbs_secret_type: kubernetes.io/dockercfg
    osbs_secret_files:
    - source: "/tmp/.dockercfg"
      dest: .dockercfg

  post_tasks:
    - name: Delete the temporary secret file
      local_action: >
        file
        state=absent
        path="/tmp/.dockercfg"

- name: Add dockercfg secret to allow registry push worker
  hosts: osbs-masters-stg[0]:osbs-masters[0]:osbs-aarch64-masters-stg[0]:osbs-aarch64-masters[0]
  tags:
    - osbs-dockercfg-secret
  user: root

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
    - name: Create the username:password string needed by the template
      set_fact:
        auth_info_prod: "{{candidate_registry_osbs_prod_username}}:{{candidate_registry_osbs_prod_password}}"
        auth_info_stg: "{{candidate_registry_osbs_stg_username}}:{{candidate_registry_osbs_stg_password}}"

    - name: Create the dockercfg secret file
      local_action: >
        template
        src="{{ files }}/osbs/dockercfg-{{env}}-secret.j2"
        dest="/tmp/.dockercfg"
        mode=0400

  roles:
    - role: osbs-secret
      osbs_namespace: "{{ osbs_worker_namespace }}"
      osbs_secret_name: "v2-registry-dockercfg"
      osbs_secret_type: kubernetes.io/dockercfg
      osbs_secret_files:
      - source: "/tmp/.dockercfg"
        dest: .dockercfg

  post_tasks:
    - name: Delete the temporary secret file
      local_action: >
        file
        state=absent
        path="/tmp/.dockercfg"

- name: post-install master host osbs tasks
  hosts: osbs-masters-stg:osbs-masters:osbs-aarch64-masters-stg[0]:osbs-aarch64-masters[0]
  tags:
    - osbs-post-install
  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - /srv/private/ansible/vars.yml
    - /srv/private/ansible/files/openstack/passwords.yml
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  vars:
    osbs_kubeconfig_path: /etc/origin/master/admin.kubeconfig
    osbs_environment:
      KUBECONFIG: "{{ osbs_kubeconfig_path }}"
    koji_pki_dir: /etc/pki/koji
    koji_ca_cert_path: "{{koji_pki_dir}}/fedora-server-ca.cert"
    koji_cert_path: "{{koji_pki_dir}}/fedora-builder.pem"
    koji_builder_user: dockerbuilder
    osbs_builder_user: builder

  tasks:
    - name: cron entry to clean up old builds
      copy:
        src: "{{files}}/osbs/cleanup-old-osbs-builds"
        dest: "/etc/cron.d/cleanup-old-osbs-builds"

- name: post-install osbs control tasks
  hosts: osbs-control
  tags: osbs-post-install
  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - /srv/private/ansible/vars.yml
    - /srv/private/ansible/files/openstack/passwords.yml
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  tasks:
    - name: enable nrpe for monitoring (noc01)
      iptables: action=insert chain=INPUT destination_port=5666 protocol=tcp source=10.5.126.41 state=present jump=ACCEPT
      tags:
      - iptables


- name: post-install osbs tasks
  hosts: osbs-nodes-stg:osbs-nodes:osbs-aarch64-nodes-stg:osbs-aarch64-nodes
  tags:
    - osbs-post-install
  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - /srv/private/ansible/vars.yml
    - /srv/private/ansible/files/openstack/passwords.yml
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  vars:
    osbs_kubeconfig_path: /etc/origin/master/admin.kubeconfig
    osbs_environment:
      KUBECONFIG: "{{ osbs_kubeconfig_path }}"
    koji_pki_dir: /etc/pki/koji
    koji_ca_cert_path: "{{koji_pki_dir}}/fedora-server-ca.cert"
    koji_cert_path: "{{koji_pki_dir}}/fedora-builder.pem"
    koji_builder_user: dockerbuilder
    osbs_builder_user: builder


  handlers:
    - name: Remove the previous buildroot image
      docker_image:
        state: absent
        name: buildroot

    - name: Build the new buildroot container
      docker_image:
        path: /etc/osbs/buildroot/
        name: buildroot
        nocache: yes

    - name: restart and reload docker service
      systemd:
        name: docker
        state: restarted
        daemon_reload: yes

  tasks:
    - name: enable nrpe for monitoring (noc01)
      iptables: action=insert chain=INPUT destination_port=5666 protocol=tcp source=10.5.126.41 state=present jump=ACCEPT
      tags:
      - iptables

    - name: copy docker iptables script
      copy:
        src: "{{files}}/osbs/fix-docker-iptables.{{ env }}"
        dest: /usr/local/bin/fix-docker-iptables
        mode: 0755
      tags:
      - iptables
      notify:
        - restart and reload docker service

    - name: copy docker custom service config
      copy:
        src: "{{files}}/osbs/docker.firewall.service"
        dest: /etc/systemd/system/docker.service.d/firewall.conf
      tags:
      - docker
      notify:
        - restart and reload docker service

    - name: copy the osbs customization file
      copy:
        src: "{{item}}"
        dest: "/etc/osbs/buildroot/"
        owner: root
        mode: 0600
      with_items:
        - "{{files}}/osbs/worker_customize.json"
        - "{{files}}/osbs/orchestrator_customize.json"

    - name: Create buildroot container conf directory
      file:
        path: "/etc/osbs/buildroot/"
        state: directory

    - name: Upload Dockerfile for buildroot container
      template:
        src: "{{ files }}/osbs/buildroot-Dockerfile-{{env}}.j2"
        dest: "/etc/osbs/buildroot/Dockerfile"
        mode: 0400
      notify:
        - Remove the previous buildroot image
        - Build the new buildroot container

    - name: Upload krb5.conf for buildroot container
      template:
        src: "{{ roles_path }}/base/templates/krb5.conf.j2"
        dest: "/etc/osbs/buildroot/krb5.conf"
        mode: 0644
      notify:
        - Remove the previous buildroot image
        - Build the new buildroot container

    - name: Upload internal CA for buildroot
      copy:
        src: "{{private}}/files/osbs/{{env}}/osbs-internal.pem"
        dest: "/etc/osbs/buildroot/ca.crt"
        mode: 0400
      notify:
        - Remove the previous buildroot image
        - Build the new buildroot container

    - name: stat infra repofile
      stat:
        path: "/etc/yum.repos.d/infra-tags.repo"
      register: infra_repo_stat

    - name: stat /etc/osbs/buildroot/ infra repofile
      stat:
        path: "/etc/osbs/buildroot/infra-tags.repo"
      register: etcosbs_infra_repo_stat

    - name: remove old /etc/osbs/buildroot/ infra repofile
      file:
        path: "/etc/osbs/buildroot/infra-tags.repo"
        state: absent
      when: etcosbs_infra_repo_stat.stat.exists and infra_repo_stat.stat.checksum != etcosbs_infra_repo_stat.stat.checksum

    - name: Copy repofile for buildroot container (because Docker)
      copy:
        src: "/etc/yum.repos.d/infra-tags.repo"
        dest: "/etc/osbs/buildroot/infra-tags.repo"
        remote_src: true
      notify:
        - Remove the previous buildroot image
        - Build the new buildroot container

      when: etcosbs_infra_repo_stat.stat.exists == false

    - name: stat /etc/ keytab
      stat:
        path: "/etc/krb5.osbs_{{osbs_url}}.keytab"
      register: etc_kt_stat

    - name: stat /etc/osbs/buildroot/ keytab
      stat:
        path: "/etc/osbs/buildroot/krb5.osbs_{{osbs_url}}.keytab"
      register: etcosbs_kt_stat

    - name: remove old hardlink to /etc/osbs/buildroot/ keytab
      file:
        path: "/etc/osbs/buildroot/krb5.osbs_{{osbs_url}}.keytab"
        state: absent
      when: etcosbs_kt_stat.stat.exists and etc_kt_stat.stat.checksum != etcosbs_kt_stat.stat.checksum

    - name: Hardlink keytab for buildroot container (because Docker)
      file:
        src: "/etc/krb5.osbs_{{osbs_url}}.keytab"
        dest: "/etc/osbs/buildroot/krb5.osbs_{{osbs_url}}.keytab"
        state: hard
      notify:
        - Remove the previous buildroot image
        - Build the new buildroot container

      when: etcosbs_kt_stat.stat.exists == false

    - name: pull fedora required docker images
      command: "docker pull {{source_registry}}/{{item}}"
      with_items: "{{fedora_required_images}}"
      register: docker_pull_fedora
      changed_when: "'Downloaded newer image' in docker_pull_fedora.stdout"

    - name: enable nrpe for monitoring (noc01)
      iptables: action=insert chain=INPUT destination_port=5666 protocol=tcp source=10.5.126.41 state=present jump=ACCEPT