config.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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: "{{ item.role }}"
  9. local_facts: "{{ item.local_facts }}"
  10. with_items:
  11. - role: common
  12. local_facts:
  13. hostname: "{{ openshift_hostname | default(None) }}"
  14. public_hostname: "{{ openshift_public_hostname | default(None) }}"
  15. deployment_type: "{{ openshift_deployment_type }}"
  16. - role: etcd
  17. local_facts: {}
  18. - name: Check status of etcd certificates
  19. stat:
  20. path: "{{ item }}"
  21. with_items:
  22. - /etc/etcd/server.crt
  23. - /etc/etcd/peer.crt
  24. - /etc/etcd/ca.crt
  25. register: g_etcd_server_cert_stat_result
  26. - set_fact:
  27. etcd_server_certs_missing: "{{ g_etcd_server_cert_stat_result.results | map(attribute='stat.exists')
  28. | list | intersect([false])}}"
  29. etcd_cert_subdir: etcd-{{ openshift.common.hostname }}
  30. etcd_cert_config_dir: /etc/etcd
  31. etcd_cert_prefix:
  32. - name: Create temp directory for syncing certs
  33. hosts: localhost
  34. connection: local
  35. sudo: false
  36. gather_facts: no
  37. tasks:
  38. - name: Create local temp directory for syncing certs
  39. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  40. register: g_etcd_mktemp
  41. changed_when: False
  42. - name: Configure etcd certificates
  43. hosts: oo_first_etcd
  44. vars:
  45. etcd_generated_certs_dir: /etc/etcd/generated_certs
  46. etcd_needing_server_certs: "{{ hostvars
  47. | oo_select_keys(groups['oo_etcd_to_config'])
  48. | oo_filter_list(filter_attr='etcd_server_certs_missing') }}"
  49. sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  50. roles:
  51. - etcd_certificates
  52. post_tasks:
  53. - name: Create a tarball of the etcd certs
  54. command: >
  55. tar -czvf {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz
  56. -C {{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }} .
  57. args:
  58. creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  59. with_items: etcd_needing_server_certs
  60. - name: Retrieve the etcd cert tarballs
  61. fetch:
  62. src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz"
  63. dest: "{{ sync_tmpdir }}/"
  64. flat: yes
  65. fail_on_missing: yes
  66. validate_checksum: yes
  67. with_items: etcd_needing_server_certs
  68. - name: Configure etcd hosts
  69. hosts: oo_etcd_to_config
  70. vars:
  71. sync_tmpdir: "{{ hostvars.localhost.g_etcd_mktemp.stdout }}"
  72. etcd_url_scheme: https
  73. etcd_peer_url_scheme: https
  74. etcd_peers_group: oo_etcd_to_config
  75. pre_tasks:
  76. - name: Ensure certificate directory exists
  77. file:
  78. path: "{{ etcd_cert_config_dir }}"
  79. state: directory
  80. - name: Unarchive the tarball on the etcd host
  81. unarchive:
  82. src: "{{ sync_tmpdir }}/{{ etcd_cert_subdir }}.tgz"
  83. dest: "{{ etcd_cert_config_dir }}"
  84. when: etcd_server_certs_missing
  85. roles:
  86. - etcd
  87. - role: nickhammond.logrotate
  88. - name: Delete temporary directory on localhost
  89. hosts: localhost
  90. connection: local
  91. sudo: false
  92. gather_facts: no
  93. tasks:
  94. - file: name={{ g_etcd_mktemp.stdout }} state=absent
  95. changed_when: False