main.yml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ---
  2. - name: Set hostname and ip facts
  3. set_fact:
  4. # Store etcd_hostname and etcd_ip such that they will be available
  5. # in hostvars. Defaults for these variables are set in etcd_common.
  6. etcd_hostname: "{{ etcd_hostname }}"
  7. etcd_ip: "{{ etcd_ip }}"
  8. - name: Install etcd
  9. action: "{{ ansible_pkg_mgr }} name=etcd state=present"
  10. when: not etcd_is_containerized | bool
  11. - name: Pull etcd container
  12. command: docker pull {{ openshift.etcd.etcd_image }}
  13. register: pull_result
  14. changed_when: "'Downloaded newer image' in pull_result.stdout"
  15. when: etcd_is_containerized | bool
  16. - name: Install etcd container service file
  17. template:
  18. dest: "/etc/systemd/system/etcd_container.service"
  19. src: etcd.docker.service
  20. register: install_etcd_result
  21. when: etcd_is_containerized | bool
  22. - name: Ensure etcd datadir exists
  23. when: etcd_is_containerized | bool
  24. file:
  25. path: "{{ etcd_data_dir }}"
  26. state: directory
  27. mode: 0700
  28. - name: Check for etcd service presence
  29. command: systemctl show etcd.service
  30. register: etcd_show
  31. changed_when: false
  32. - name: Disable system etcd when containerized
  33. when: etcd_is_containerized | bool and 'LoadState=not-found' not in etcd_show.stdout
  34. service:
  35. name: etcd
  36. state: stopped
  37. enabled: no
  38. - name: Mask system etcd when containerized
  39. when: etcd_is_containerized | bool and 'LoadState=not-found' not in etcd_show.stdout
  40. command: systemctl mask etcd
  41. - name: Reload systemd units
  42. command: systemctl daemon-reload
  43. when: etcd_is_containerized | bool and ( install_etcd_result | changed )
  44. - name: Validate permissions on the config dir
  45. file:
  46. path: "{{ etcd_conf_dir }}"
  47. state: directory
  48. owner: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
  49. group: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
  50. mode: 0700
  51. - name: Write etcd global config file
  52. template:
  53. src: etcd.conf.j2
  54. dest: /etc/etcd/etcd.conf
  55. backup: true
  56. notify:
  57. - restart etcd
  58. - name: Enable etcd
  59. service:
  60. name: "{{ etcd_service }}"
  61. state: started
  62. enabled: yes
  63. register: start_result
  64. - set_fact:
  65. etcd_service_status_changed: "{{ start_result | changed }}"