summaryrefslogtreecommitdiffstats
path: root/roles/etcd/tasks/main.yml
blob: 586aebb11a6d729cc2c254a216f5727f4c30c728 (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
125
126
127
128
129
130
131
---
- 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
  package: name=etcd{{ '-' + etcd_version if etcd_version is defined else '' }} state=present
  when: not etcd_is_containerized | bool

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

  - name: Install etcd container service file
    template:
      dest: "/etc/systemd/system/etcd_container.service"
      src: etcd.docker.service
  when:
  - etcd_is_containerized | bool
  - not openshift.common.is_etcd_system_container | bool

# Start secondary etcd instance for third party integrations
# TODO: Determine an alternative to using thirdparty variable
- block:
  - name: Create configuration directory
    file:
      path: "{{ etcd_conf_dir }}"
      state: directory
      mode: 0700

  # TODO: retest with symlink to confirm it does or does not function
  - name: Copy service file for etcd instance
    copy:
      src: /usr/lib/systemd/system/etcd.service
      dest: "/etc/systemd/system/{{ etcd_service }}.service"
      remote_src: True

  - name: Create third party etcd service.d directory exists
    file:
      path: "{{ etcd_systemd_dir }}"
      state: directory

  - name: Configure third part etcd service unit file
    template:
      dest: "{{ etcd_systemd_dir }}/custom.conf"
      src: custom.conf.j2
  when: etcd_is_thirdparty

  # TODO: this task may not be needed with Validate permissions
- name: Ensure etcd datadir exists
  file:
    path: "{{ etcd_data_dir }}"
    state: directory
    mode: 0700
  when: etcd_is_containerized | bool

- name: Ensure etcd datadir ownership for thirdparty datadir
  file:
    path: "{{ etcd_data_dir }}"
    state: directory
    mode: 0700
    owner: etcd
    group: etcd
    recurse: True
  when: etcd_is_thirdparty | bool

  # TODO: Determine if the below reload would work here, for now just reload
- name:
  command: systemctl daemon-reload
  when: etcd_is_thirdparty | bool

- block:
  - name: Disable system etcd when containerized
    systemd:
      name: etcd
      state: stopped
      enabled: no
      masked: yes
      daemon_reload: yes
    when: not openshift.common.is_etcd_system_container | bool
    register: task_result
    failed_when: task_result|failed and 'could not' not in task_result.msg|lower

  - name: Install etcd container service file
    template:
      dest: "/etc/systemd/system/etcd_container.service"
      src: etcd.docker.service
    when: not openshift.common.is_etcd_system_container | bool

  - name: Install Etcd system container
    include: system_container.yml
    when: openshift.common.is_etcd_system_container | bool
  when: etcd_is_containerized | bool

- 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: Write etcd global config file
  template:
    src: etcd.conf.j2
    dest: "{{ etcd_conf_file }}"
    backup: true
  notify:
  - restart etcd

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

- include_role:
    name: etcd_common
  vars:
    r_etcd_common_action: drop_etcdctl
  when: openshift_etcd_etcdctl_profile | default(true) | bool

- name: Set fact etcd_service_status_changed
  set_fact:
    etcd_service_status_changed: "{{ start_result | changed }}"