summaryrefslogtreecommitdiffstats
path: root/playbooks/common/openshift-etcd/config.yml
blob: 3d7a884e870a9f29c3c70cb540d99ef27a673a3d (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
---
- name: Set etcd facts needed for generating certs
  hosts: oo_etcd_to_config
  roles:
  - openshift_facts
  tasks:
  - openshift_facts:
      role: "{{ item.role }}"
      local_facts: "{{ item.local_facts }}"
    with_items:
      - role: common
        local_facts:
          hostname: "{{ openshift_hostname | default(None) }}"
          public_hostname: "{{ openshift_public_hostname | default(None) }}"
          deployment_type: "{{ openshift_deployment_type }}"
      - role: etcd
        local_facts: {}
  - name: Check status of etcd certificates
    stat:
      path: "{{ item }}"
    with_items:
    - /etc/etcd/server.crt
    - /etc/etcd/peer.crt
    - /etc/etcd/ca.crt
    register: g_etcd_server_cert_stat_result
  - set_fact:
      etcd_server_certs_missing: "{{ g_etcd_server_cert_stat_result.results | oo_collect(attribute='stat.exists')
                                    | list | intersect([false])}}"
      etcd_cert_subdir: etcd-{{ openshift.common.hostname }}
      etcd_cert_config_dir: /etc/etcd
      etcd_cert_prefix:

- name: Create temp directory for syncing certs
  hosts: localhost
  connection: local
  sudo: false
  gather_facts: no
  tasks:
  - name: Create local temp directory for syncing certs
    local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
    register: g_etcd_mktemp
    changed_when: False

- name: Configure etcd certificates
  hosts: oo_first_etcd
  vars:
    etcd_generated_certs_dir: /etc/etcd/generated_certs
    etcd_needing_server_certs: "{{ hostvars
                                  | oo_select_keys(groups['oo_etcd_to_config'])
                                  | oo_filter_list(filter_attr='etcd_server_certs_missing') }}"
    sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  roles:
  - etcd_certificates
  post_tasks:
  - name: Create a tarball of the etcd certs
    command: >
      tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
        -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
    args:
      creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
    with_items: etcd_needing_server_certs
  - name: Retrieve the etcd cert tarballs
    fetch:
      src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
      dest: "{{ sync_tmpdir }}/"
      flat: yes
      fail_on_missing: yes
      validate_checksum: yes
    with_items: etcd_needing_server_certs

# Configure a first etcd host to avoid conflicts in choosing a leader
# if other members come online too quickly.
- name: Configure first etcd host
  hosts: oo_first_etcd
  vars:
    sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
    etcd_url_scheme: https
    etcd_peer_url_scheme: https
    etcd_peers_group: oo_etcd_to_config
  pre_tasks:
  - name: Ensure certificate directory exists
    file:
      path: "{{ etcd_cert_config_dir }}"
      state: directory
  - name: Unarchive the tarball on the etcd host
    unarchive:
      src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
      dest: "{{ etcd_cert_config_dir }}"
    when: etcd_server_certs_missing
  roles:
  - etcd
  - role: nickhammond.logrotate

# Configure the remaining etcd hosts, skipping the first one we dealt with above.
- name: Configure remaining etcd hosts
  hosts: oo_etcd_to_config:!oo_first_etcd
  vars:
    sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
    etcd_url_scheme: https
    etcd_peer_url_scheme: https
    etcd_peers_group: oo_etcd_to_config
  pre_tasks:
  - name: Ensure certificate directory exists
    file:
      path: "{{ etcd_cert_config_dir }}"
      state: directory
  - name: Unarchive the tarball on the etcd host
    unarchive:
      src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
      dest: "{{ etcd_cert_config_dir }}"
    when: etcd_server_certs_missing
  roles:
  - etcd
  - role: nickhammond.logrotate

- name: Delete temporary directory on localhost
  hosts: localhost
  connection: local
  sudo: false
  gather_facts: no
  tasks:
  - file: name={{ g_etcd_mktemp.stdout }} state=absent
    changed_when: False