deploy_ca.yml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ---
  2. - name: Install openssl
  3. package:
  4. name: openssl
  5. state: present
  6. when: not etcd_is_atomic | bool
  7. delegate_to: "{{ etcd_ca_host }}"
  8. run_once: true
  9. register: result
  10. until: result is succeeded
  11. - file:
  12. path: "{{ item }}"
  13. state: directory
  14. mode: 0700
  15. owner: root
  16. group: root
  17. with_items:
  18. - "{{ etcd_ca_new_certs_dir }}"
  19. - "{{ etcd_ca_crl_dir }}"
  20. - "{{ etcd_ca_dir }}/fragments"
  21. delegate_to: "{{ etcd_ca_host }}"
  22. run_once: true
  23. - command: cp /etc/pki/tls/openssl.cnf ./
  24. args:
  25. chdir: "{{ etcd_ca_dir }}/fragments"
  26. creates: "{{ etcd_ca_dir }}/fragments/openssl.cnf"
  27. delegate_to: "{{ etcd_ca_host }}"
  28. run_once: true
  29. - template:
  30. dest: "{{ etcd_ca_dir }}/fragments/openssl_append.cnf"
  31. src: openssl_append.j2
  32. backup: true
  33. delegate_to: "{{ etcd_ca_host }}"
  34. run_once: true
  35. - assemble:
  36. src: "{{ etcd_ca_dir }}/fragments"
  37. dest: "{{ etcd_openssl_conf }}"
  38. delegate_to: "{{ etcd_ca_host }}"
  39. run_once: true
  40. - name: Check etcd_ca_db exist
  41. stat:
  42. path: "{{ etcd_ca_db }}"
  43. get_checksum: false
  44. get_mime: false
  45. register: etcd_ca_db_check
  46. changed_when: false
  47. delegate_to: "{{ etcd_ca_host }}"
  48. run_once: true
  49. - name: Touch etcd_ca_db file
  50. file:
  51. path: "{{ etcd_ca_db }}"
  52. state: touch
  53. when: etcd_ca_db_check.stat.isreg is not defined
  54. delegate_to: "{{ etcd_ca_host }}"
  55. run_once: true
  56. - copy:
  57. dest: "{{ etcd_ca_serial }}"
  58. content: "01"
  59. force: no
  60. delegate_to: "{{ etcd_ca_host }}"
  61. run_once: true
  62. - name: Create etcd CA certificate
  63. command: >
  64. openssl req -config {{ etcd_openssl_conf }} -newkey rsa:4096
  65. -keyout {{ etcd_ca_key }} -new -out {{ etcd_ca_cert }}
  66. -x509 -extensions {{ etcd_ca_exts_self }} -batch -nodes
  67. -days {{ etcd_ca_default_days }}
  68. -subj /CN=etcd-signer@{{ ansible_date_time.epoch }}
  69. args:
  70. chdir: "{{ etcd_ca_dir }}"
  71. creates: "{{ etcd_ca_cert }}"
  72. environment:
  73. SAN: 'etcd-signer'
  74. delegate_to: "{{ etcd_ca_host }}"
  75. run_once: true