config.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ---
  2. - name: Set etcd facts needed for generating certs
  3. hosts: oo_etcd_to_config
  4. roles:
  5. - openshift_facts
  6. tasks:
  7. - openshift_facts:
  8. role: etcd
  9. local_facts:
  10. etcd_image: "{{ osm_etcd_image | default(None) }}"
  11. - name: Check status of etcd certificates
  12. stat:
  13. path: "{{ item }}"
  14. with_items:
  15. - /etc/etcd/server.crt
  16. - /etc/etcd/peer.crt
  17. - /etc/etcd/ca.crt
  18. register: g_etcd_server_cert_stat_result
  19. - set_fact:
  20. etcd_server_certs_missing: "{{ g_etcd_server_cert_stat_result.results | oo_collect(attribute='stat.exists')
  21. | list | intersect([false])}}"
  22. etcd_cert_subdir: etcd-{{ openshift.common.hostname }}
  23. etcd_cert_config_dir: /etc/etcd
  24. etcd_cert_prefix:
  25. etcd_hostname: "{{ openshift.common.hostname }}"
  26. etcd_ip: "{{ openshift.common.ip }}"
  27. - name: Create temp directory for syncing certs
  28. hosts: localhost
  29. connection: local
  30. become: no
  31. gather_facts: no
  32. tasks:
  33. - name: Create local temp directory for syncing certs
  34. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  35. register: g_etcd_mktemp
  36. changed_when: False
  37. - name: Configure etcd certificates
  38. hosts: oo_first_etcd
  39. vars:
  40. etcd_generated_certs_dir: /etc/etcd/generated_certs
  41. etcd_needing_server_certs: "{{ hostvars
  42. | oo_select_keys(groups['oo_etcd_to_config'])
  43. | oo_filter_list(filter_attr='etcd_server_certs_missing') }}"
  44. sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  45. roles:
  46. - openshift_etcd_certificates
  47. post_tasks:
  48. - name: Create a tarball of the etcd certs
  49. command: >
  50. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  51. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  52. args:
  53. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  54. with_items: etcd_needing_server_certs
  55. - name: Retrieve the etcd cert tarballs
  56. fetch:
  57. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  58. dest: "{{ sync_tmpdir }}/"
  59. flat: yes
  60. fail_on_missing: yes
  61. validate_checksum: yes
  62. with_items: etcd_needing_server_certs
  63. # Configure a first etcd host to avoid conflicts in choosing a leader
  64. # if other members come online too quickly.
  65. - name: Configure first etcd host
  66. hosts: oo_first_etcd
  67. vars:
  68. sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  69. etcd_url_scheme: https
  70. etcd_peer_url_scheme: https
  71. etcd_peers: "{{ groups.oo_etcd_to_config | default([], true) }}"
  72. pre_tasks:
  73. - name: Ensure certificate directory exists
  74. file:
  75. path: "{{ etcd_cert_config_dir }}"
  76. state: directory
  77. - name: Unarchive the tarball on the etcd host
  78. unarchive:
  79. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  80. dest: "{{ etcd_cert_config_dir }}"
  81. when: etcd_server_certs_missing
  82. roles:
  83. - openshift_etcd
  84. - nickhammond.logrotate
  85. # Configure the remaining etcd hosts, skipping the first one we dealt with above.
  86. - name: Configure remaining etcd hosts
  87. hosts: oo_etcd_to_config:!oo_first_etcd
  88. vars:
  89. sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  90. etcd_url_scheme: https
  91. etcd_peer_url_scheme: https
  92. etcd_peers: "{{ groups.oo_etcd_to_config | default([], true) }}"
  93. pre_tasks:
  94. - name: Ensure certificate directory exists
  95. file:
  96. path: "{{ etcd_cert_config_dir }}"
  97. state: directory
  98. - name: Unarchive the tarball on the etcd host
  99. unarchive:
  100. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  101. dest: "{{ etcd_cert_config_dir }}"
  102. when: etcd_server_certs_missing
  103. roles:
  104. - openshift_etcd
  105. - role: nickhammond.logrotate
  106. - name: Delete temporary directory on localhost
  107. hosts: localhost
  108. connection: local
  109. become: no
  110. gather_facts: no
  111. tasks:
  112. - file: name={{ g_etcd_mktemp.stdout }} state=absent
  113. changed_when: False