config.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. - name: Create temp directory for syncing certs
  26. hosts: localhost
  27. connection: local
  28. become: no
  29. gather_facts: no
  30. tasks:
  31. - name: Create local temp directory for syncing certs
  32. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  33. register: g_etcd_mktemp
  34. changed_when: False
  35. - name: Configure etcd certificates
  36. hosts: oo_first_etcd
  37. vars:
  38. etcd_generated_certs_dir: /etc/etcd/generated_certs
  39. etcd_needing_server_certs: "{{ hostvars
  40. | oo_select_keys(groups['oo_etcd_to_config'])
  41. | oo_filter_list(filter_attr='etcd_server_certs_missing') }}"
  42. sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  43. roles:
  44. - etcd_certificates
  45. post_tasks:
  46. - name: Create a tarball of the etcd certs
  47. command: >
  48. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  49. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  50. args:
  51. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  52. with_items: etcd_needing_server_certs
  53. - name: Retrieve the etcd cert tarballs
  54. fetch:
  55. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  56. dest: "{{ sync_tmpdir }}/"
  57. flat: yes
  58. fail_on_missing: yes
  59. validate_checksum: yes
  60. with_items: etcd_needing_server_certs
  61. # Configure a first etcd host to avoid conflicts in choosing a leader
  62. # if other members come online too quickly.
  63. - name: Configure first etcd host
  64. hosts: oo_first_etcd
  65. vars:
  66. sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  67. etcd_url_scheme: https
  68. etcd_peer_url_scheme: https
  69. etcd_peers_group: oo_etcd_to_config
  70. pre_tasks:
  71. - name: Ensure certificate directory exists
  72. file:
  73. path: "{{ etcd_cert_config_dir }}"
  74. state: directory
  75. - name: Unarchive the tarball on the etcd host
  76. unarchive:
  77. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  78. dest: "{{ etcd_cert_config_dir }}"
  79. when: etcd_server_certs_missing
  80. roles:
  81. - openshift_etcd
  82. - nickhammond.logrotate
  83. # Configure the remaining etcd hosts, skipping the first one we dealt with above.
  84. - name: Configure remaining etcd hosts
  85. hosts: oo_etcd_to_config:!oo_first_etcd
  86. vars:
  87. sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  88. etcd_url_scheme: https
  89. etcd_peer_url_scheme: https
  90. etcd_peers_group: oo_etcd_to_config
  91. pre_tasks:
  92. - name: Ensure certificate directory exists
  93. file:
  94. path: "{{ etcd_cert_config_dir }}"
  95. state: directory
  96. - name: Unarchive the tarball on the etcd host
  97. unarchive:
  98. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  99. dest: "{{ etcd_cert_config_dir }}"
  100. when: etcd_server_certs_missing
  101. roles:
  102. - openshift_etcd
  103. - role: nickhammond.logrotate
  104. - name: Delete temporary directory on localhost
  105. hosts: localhost
  106. connection: local
  107. become: no
  108. gather_facts: no
  109. tasks:
  110. - file: name={{ g_etcd_mktemp.stdout }} state=absent
  111. changed_when: False