summaryrefslogtreecommitdiffstats
path: root/roles/etcd/tasks/system_container.yml
blob: a01df66b3a1cec2936e7fb8bdaaf1987d80f59b7 (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
---
- name: Pull etcd system container
  command: atomic pull --storage=ostree {{ openshift.etcd.etcd_image }}
  register: pull_result
  changed_when: "'Pulling layer' in pull_result.stdout"

- name: Set initial Etcd cluster
  set_fact:
    etcd_initial_cluster: >-
      {% for host in etcd_peers | default([]) -%}
      {% if loop.last -%}
      {{ hostvars[host].etcd_hostname }}={{ etcd_peer_url_scheme }}://{{ hostvars[host].etcd_ip }}:{{ etcd_peer_port }}
      {%- else -%}
      {{ hostvars[host].etcd_hostname }}={{ etcd_peer_url_scheme }}://{{ hostvars[host].etcd_ip }}:{{ etcd_peer_port }},
      {%- endif -%}
      {% endfor -%}

- name: Check etcd system container package
  command: >
    atomic containers list --no-trunc -a -f container=etcd -f backend=ostree
  register: etcd_result

- name: Unmask etcd service
  systemd:
    name: etcd
    state: stopped
    enabled: no
    masked: no
    daemon_reload: yes
  register: task_result
  failed_when: task_result|failed and 'could not' not in task_result.msg|lower
  when: "'etcd' not in etcd_result.stdout"

- name: Disable etcd_container
  systemd:
    name: etcd_container
    state: stopped
    enabled: no
    daemon_reload: yes
  register: task_result
  failed_when: task_result|failed and 'could not' not in task_result.msg|lower

- name: Remove etcd_container.service
  file:
    path: /etc/systemd/system/etcd_container.service
    state: absent

- name: Systemd reload configuration
  systemd: name=etcd_container daemon_reload=yes

- name: Check for previous etcd data store
  stat:
    path: "{{ etcd_data_dir }}/member/"
  register: src_datastore

- name: Check for etcd system container data store
  stat:
    path: "{{ r_etcd_common_system_container_host_dir }}/etcd.etcd/member"
  register: dest_datastore

- name: Ensure that etcd system container data dirs exist
  file: path="{{ item }}" state=directory
  with_items:
    - "{{ r_etcd_common_system_container_host_dir }}/etc"
    - "{{ r_etcd_common_system_container_host_dir }}/etcd.etcd"

- name: Copy etcd data store
  command: >
    cp -a {{ etcd_data_dir }}/member
    {{ r_etcd_common_system_container_host_dir }}/etcd.etcd/member
  when:
    - src_datastore.stat.exists
    - not dest_datastore.stat.exists

- name: Install or Update Etcd system container package
  oc_atomic_container:
    name: etcd
    image: "{{ openshift.etcd.etcd_image }}"
    state: latest
    values:
      - ETCD_LISTEN_PEER_URLS={{ etcd_listen_peer_urls }}
      - ETCD_NAME={{ etcd_hostname }}
      - ETCD_INITIAL_CLUSTER={{ etcd_initial_cluster }}
      - ETCD_LISTEN_CLIENT_URLS={{ etcd_listen_client_urls }}
      - ETCD_INITIAL_ADVERTISE_PEER_URLS={{ etcd_initial_advertise_peer_urls }}
      - ETCD_INITIAL_CLUSTER_STATE={{ etcd_initial_cluster_state }}
      - ETCD_INITIAL_CLUSTER_TOKEN={{ etcd_initial_cluster_token }}
      - ETCD_ADVERTISE_CLIENT_URLS={{ etcd_advertise_client_urls }}
      - ETCD_CA_FILE={{ etcd_system_container_conf_dir }}/ca.crt
      - ETCD_CERT_FILE={{ etcd_system_container_conf_dir }}/server.crt
      - ETCD_KEY_FILE={{ etcd_system_container_conf_dir }}/server.key
      - ETCD_PEER_CA_FILE={{ etcd_system_container_conf_dir }}/ca.crt
      - ETCD_PEER_CERT_FILE={{ etcd_system_container_conf_dir }}/peer.crt
      - ETCD_PEER_KEY_FILE={{ etcd_system_container_conf_dir }}/peer.key
      - ETCD_TRUSTED_CA_FILE={{ etcd_system_container_conf_dir }}/ca.crt
      - ETCD_PEER_TRUSTED_CA_FILE={{ etcd_system_container_conf_dir }}/ca.crt