Wolfgang Kulhanek
2018-07-26 1aed44ab83a57e4fc0ad92a9d032e8e7418d079e
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
---
- name: Step 00xxxxx software
  hosts: localhost
  gather_facts: False
  become: false
  vars_files:
    - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_vars.yml"
    - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_secret_vars.yml"
  tasks:
    - debug:
        msg: "Software tasks started"
 
- name: Preflight Checks
  hosts: localhost
  tasks:
    - name: Validate Required Group Configuration
      fail:
        msg: "'database', 'redis' and 'quay_enterprise' groups must be specified"
      when:
        - "'redis' not in groups or groups['redis']| length == 0 or 'database' not in groups or groups['database']| length == 0 or 'quay_enterprise' not in groups or groups['quay_enterprise']| length == 0"
 
- name: Set up Node Software (Docker)
  hosts: bastions
  gather_facts: false
  become: true
  vars_files:
    - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_vars.yml"
    - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_secret_vars.yml"
  roles:
    - ../../roles/host-ocp-node
 
- name: Install and Configure Database
  hosts: database
  gather_facts: false
  become: true
  vars_files:
    - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_vars.yml"
    - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_secret_vars.yml"
  tasks:
    - name: Install MySQL
      include_role:
        name: ../../roles/config-mysql
      vars:
        mode: containerized
        mysql_username: "{{ database_username }}"
        mysql_password: "{{ database_password }}"
        mysql_root_username: "{{ database_admin_username }}"
        mysql_root_password: "{{ database_admin_password }}"
        mysql_database: "{{ database_name }}"
      when: database_type == "mysql"
 
    - name: Install and Configure PostgreSQL
      block:
        - name: Install PostgreSQL
          include_role:
            name: ../../roles/config-postgresql
          vars:
            mode: containerized
            postgresql_username: "{{ database_username }}"
            postgresql_password: "{{ database_password }}"
            postgresql_admin_user: "{{ database_admin_username }}"
            postgresql_admin_password: "{{ database_admin_password }}"
            postgresql_database: "{{ database_name }}"
        
        - name: Flush Handlers
          meta: flush_handlers
 
        - name: Locate PostgreSQL Container
          command: docker ps --filter=name=postgresql.service -q
          register: postgresql_container
 
        - name: Sleep to give PostgreSQL a chance to finish starting up
          pause:
            seconds: 10
          
        - name: Configure PostgreSQL
          shell: docker exec -i {{ postgresql_container.stdout }} /bin/bash -c 'PGPASSWORD={{ database_admin_password }} psql {{ database_name }} -c "CREATE EXTENSION pg_trgm;"'
          register: shell_result
          failed_when:
            - shell_result.rc != 0
            - "'already exists' not in shell_result.stderr"
      when: database_type == "postgresql"
 
- name: Install Redis
  hosts: redis
  become: true
  tasks:
    - name: Install Redis
      include_role:
        name: ../../roles/config-redis
      vars:
        mode: containerized
 
- name: Install Quay Enterprise
  hosts: quay_enterprise
  gather_facts: false
  become: true
  vars_files:
    - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_vars.yml"
    - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_secret_vars.yml"
  tasks:
    - name: Install Quay
      include_role:
        name: ../../roles/config-quay-enterprise
      vars:
        quay_ssl_generate_hostname: "{{ quay_hostname }}.{{subdomain_base}}"
        database_host: "{{ hostvars[groups['database'][0]]['ansible_eth0']['ipv4']['address'] }}"
        redis_host: "{{ hostvars[groups['redis'][0]]['ansible_eth0']['ipv4']['address'] }}"
 
- name: Software flight-check
  hosts: localhost
  connection: local
  gather_facts: false
  become: false
  tags:
    - post_flight_check
  tasks:
    - debug:
        msg: "Software checks completed successfully"