main.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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: Validate permissions on certificate files
  52. file:
  53. path: "{{ item }}"
  54. mode: 0600
  55. owner: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
  56. group: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
  57. when: etcd_url_scheme == 'https'
  58. with_items:
  59. - "{{ etcd_ca_file }}"
  60. - "{{ etcd_cert_file }}"
  61. - "{{ etcd_key_file }}"
  62. - name: Validate permissions on peer certificate files
  63. file:
  64. path: "{{ item }}"
  65. mode: 0600
  66. owner: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
  67. group: "{{ 'etcd' if not etcd_is_containerized | bool else omit }}"
  68. when: etcd_peer_url_scheme == 'https'
  69. with_items:
  70. - "{{ etcd_peer_ca_file }}"
  71. - "{{ etcd_peer_cert_file }}"
  72. - "{{ etcd_peer_key_file }}"
  73. - name: Write etcd global config file
  74. template:
  75. src: etcd.conf.j2
  76. dest: /etc/etcd/etcd.conf
  77. backup: true
  78. notify:
  79. - restart etcd
  80. - name: Enable etcd
  81. service:
  82. name: "{{ etcd_service }}"
  83. state: started
  84. enabled: yes
  85. register: start_result
  86. - set_fact:
  87. etcd_service_status_changed: "{{ start_result | changed }}"