summaryrefslogtreecommitdiffstats
path: root/roles/etcd/tasks/main.yml
blob: 75d40216d41afe7445333a0870e4b9411bb95130 (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
---
- name: Set hostname and ip facts
  set_fact:
    # Store etcd_hostname and etcd_ip such that they will be available
    # in hostvars. Defaults for these variables are set in etcd_common.
    etcd_hostname: "{{ etcd_hostname }}"
    etcd_ip: "{{ etcd_ip }}"

- name: Install etcd
  action: "{{ ansible_pkg_mgr }} name=etcd state=present"
  when: not etcd_is_containerized | bool

- name: Pull etcd container
  command: docker pull {{ openshift.etcd.etcd_image }}
  register: pull_result
  changed_when: "'Downloaded newer image' in pull_result.stdout"
  when: etcd_is_containerized | bool

- name: Install etcd container service file
  template:
    dest: "/etc/systemd/system/etcd_container.service"
    src: etcd.docker.service
  register: install_etcd_result
  when: etcd_is_containerized | bool

- name: Ensure etcd datadir exists
  when: etcd_is_containerized | bool
  file:
    path: "{{ etcd_data_dir }}"
    state: directory
    mode: 0700

- name: Check for etcd service presence
  command: systemctl show etcd.service
  register: etcd_show
  changed_when: false

- name: Disable system etcd when containerized
  when: etcd_is_containerized | bool and 'LoadState=not-found' not in etcd_show.stdout
  service:
    name: etcd
    state: stopped
    enabled: no

- name: Mask system etcd when containerized
  when: etcd_is_containerized | bool and 'LoadState=not-found' not in etcd_show.stdout
  command: systemctl mask etcd

- name: Reload systemd units
  command: systemctl daemon-reload
  when: etcd_is_containerized | bool and ( install_etcd_result | changed )

- name: Validate permissions on the config dir
  file:
    path: "{{ etcd_conf_dir }}"
    state: directory
    owner: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
    group: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
    mode: 0700

- name: Validate permissions on certificate files
  file:
    path: "{{ item }}"
    mode: 0600
    owner: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
    group: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
  when: etcd_url_scheme == 'https'
  with_items:
  - "{{ etcd_ca_file }}"
  - "{{ etcd_cert_file }}"
  - "{{ etcd_key_file }}"

- name: Validate permissions on peer certificate files
  file:
    path: "{{ item }}"
    mode: 0600
    owner: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
    group: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
  when: etcd_peer_url_scheme == 'https'
  with_items:
  - "{{ etcd_peer_ca_file }}"
  - "{{ etcd_peer_cert_file }}"
  - "{{ etcd_peer_key_file }}"

- name: Write etcd global config file
  template:
    src: etcd.conf.j2
    dest: /etc/etcd/etcd.conf
    backup: true
  notify:
    - restart etcd

- name: Enable etcd
  service:
    name: "{{ etcd_service }}"
    state: started
    enabled: yes
  register: start_result

- set_fact:
    etcd_service_status_changed: "{{ start_result | changed }}"