summaryrefslogtreecommitdiffstats
path: root/playbooks/gce/openshift-node/config.yml
blob: 17631d578216edfc00d03962e88649f4a7574fd8 (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
- name: node/config.yml, populate oo_nodes_to_config host group if needed
  hosts: localhost
  gather_facts: no
  tasks:
  - name: Evaluate oo_host_group_exp
    add_host: "name={{ item }} groups=oo_nodes_to_config"
    with_items: "{{ oo_host_group_exp | default('') }}"
    when: oo_host_group_exp is defined
 - name: Find masters for env
    add_host: "name={{ item }} groups=oo_masters_for_node_config"
    with_items: groups['tag_env-host-type-' + oo_env + '-openshift-master']

- name: Gather facts for masters in {{ oo_env }}
  hosts: "tag_env-host-type-{{ oo_env }}-openshift-master"
  tasks:
  - set_fact:
      openshift_master_ip: "{{ openshift_ip }}"
      openshift_master_api_url: "{{ openshift_api_url }}"
      openshift_master_webui_url: "{{ openshift_webui_url }}"
      openshift_master_hostname: "{{ openshift_hostname }}"
      openshift_master_public_ip: "{{ openshift_public_ip }}"
      openshift_master_api_public_url: "{{ openshift_api_public_url }}"
      openshift_master_webui_public_url: "{{ openshift_webui_public_url }}"
      openshift_master_public_hostnames: "{{ openshift_public_hostname }}"

- name: Gather facts for hosts to configure
  hosts: tag_env-host-type-{{ oo_env }}-openshift-node
  tasks:
  - set_fact:
      openshift_node_hostname: "{{ openshift_hostname }}"
      openshift_node_name: "{{ openshift_hostname }}"
      openshift_node_cpu: "{{ openshift_node_cpu if openshift_node_cpu else ansible_processor_cores }}"
      openshift_node_memory: "{{ openshift_node_memory if openshift_node_memory else (ansible_memtotal_mb|int * 1024 * 1024 * 0.75)|int }}"
      openshift_node_pod_cidr: "{{ openshift_node_pod_cidr if openshift_node_pod_cidr else None }}"
      openshift_node_host_ip: "{{ openshift_ip }}"
      openshift_node_labels: "{{ openshift_node_labels if openshift_node_labels else {} }}"
      openshift_node_annotations: "{{ openshift_node_annotations if openshift_node_annotations else {} }}"

- name: Register nodes
  hosts: tag_env-host-type-{{ oo_env }}-openshift-master[0]
  vars:
    openshift_node_group: tag_env-host-type-{{ oo_env }}-openshift-node
    openshift_nodes: "{{ hostvars
          | oo_select_keys(groups[openshift_node_group]) }}"
    openshift_master_group: tag_env-host-type-{{ oo_env }}-openshift-master
    openshift_master_urls: "{{ hostvars
          | oo_select_keys(groups[openshift_master_group])
          | oo_collect(attribute='openshift_master_api_url') }}"
    openshift_master_public_urls: "{{ hostvars
          | oo_select_keys(groups[openshift_master_group])
          | oo_collect(attribute='openshift_master_api_public_url') }}"
  pre_tasks:
  roles:
  - openshift_register_nodes
  tasks:
  - name: Create local temp directory for syncing certs
    local_action: command /usr/bin/mktemp -d /tmp/openshift-ansible-XXXXXXX
    register: mktemp

  - name: Sync master certs to localhost
    synchronize:
      mode: pull
      checksum: yes
      src: /var/lib/openshift/openshift.local.certificates
      dest: "{{ mktemp.stdout }}"

# TODO: sync generated certs between masters
#
- name: Configure instances
  hosts: oo_nodes_to_config
  vars_files:
  - vars.yml
  vars:
    openshift_master_group: tag_env-host-type-{{ oo_env }}-openshift-master
    openshift_master_ips: "{{ hostvars
          | oo_select_keys(groups[openshift_master_group])
          | oo_collect(attribute='openshift_master_ip') }}"
    openshift_master_hostnames: "{{ hostvars
          | oo_select_keys(groups[openshift_master_group])
          | oo_collect(attribute='openshift_master_hostname') }}"
    openshift_master_public_ips: "{{ hostvars
          | oo_select_keys(groups[openshift_master_group])
          | oo_collect(attribute='openshift_master_public_ip') }}"
    openshift_master_public_hostnames: "{{ hostvars
          | oo_select_keys(groups[openshift_master_group])
          | oo_collect(attribute='openshift_master_public_hostname') }}"
    cert_parent_rel_path: openshift.local.certificates
    cert_rel_path: "{{ cert_parent_rel_path }}/node-{{ openshift_node_name }}"
    cert_base_path: /var/lib/openshift
    cert_parent_path: "{{ cert_base_path }}/{{ cert_parent_rel_path }}"
    cert_path: "{{ cert_base_path }}/{{ cert_rel_path }}"
  pre_tasks:
  - name: Ensure certificate directories exists
    file:
      path: "{{ item }}"
      state: directory
    with_items:
    - "{{ cert_path }}"
    - "{{ cert_parent_path }}/ca"

  # TODO: only sync to a node if it's certs have been updated
  # TODO: notify restart openshift-node and/or restart openshift-sdn-node,
  # possibly test service started time against certificate/config file
  # timestamps in openshift-node or openshift-sdn-node to trigger notify
  # TODO: also copy ca cert: /var/lib/openshift/openshift.local.certificates/ca/cert.crt
  - name: Sync certs to nodes
    synchronize:
      checksum: yes
      src: "{{ item.src }}"
      dest: "{{ item.dest }}"
      owner: no
      group: no
    with_items:
    - src: "{{ hostvars[groups[openshift_master_group][0]].mktemp.stdout }}/{{ cert_rel_path }}"
      dest: "{{ cert_parent_path }}"
    - src: "{{ hostvars[groups[openshift_master_group][0]].mktemp.stdout }}/{{ cert_parent_rel_path }}/ca/cert.crt"
      dest: "{{ cert_parent_path }}/ca/cert.crt"
  - local_action: file name={{ hostvars[groups[openshift_master_group][0]].mktemp.stdout }} state=absent
    run_once: true
  roles:
    - openshift_node
    - os_env_extras
    - os_env_extras_node