api_proxy.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ---
  2. - name: API proxy | Create contiv-api-proxy openshift user
  3. oc_serviceaccount:
  4. state: present
  5. name: contiv-api-proxy
  6. namespace: kube-system
  7. run_once: true
  8. - name: API proxy | Set contiv-api-proxy openshift user permissions
  9. oc_adm_policy_user:
  10. user: system:serviceaccount:kube-system:contiv-api-proxy
  11. resource_kind: scc
  12. resource_name: hostnetwork
  13. state: present
  14. run_once: true
  15. - name: API proxy | Create temp directory for doing work
  16. command: mktemp -d /tmp/openshift-contiv-XXXXXX
  17. register: mktemp
  18. changed_when: False
  19. # For things that pass temp files between steps, we want to make sure they
  20. # run on the same node.
  21. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  22. run_once: true
  23. - name: API proxy | Check for existing api proxy secret volume
  24. oc_obj:
  25. namespace: kube-system
  26. kind: secret
  27. state: list
  28. selector: "name=contiv-api-proxy-secret"
  29. register: existing_secret_volume
  30. run_once: true
  31. - name: API proxy | Generate a self signed certificate for api proxy
  32. command: openssl req -new -nodes -x509 -subj "/C=US/ST=/L=/O=/CN=localhost" -days 3650 -keyout "{{ mktemp.stdout }}/key.pem" -out "{{ mktemp.stdout }}/cert.pem" -extensions v3_ca
  33. when: (contiv_api_proxy_cert is not defined or contiv_api_proxy_key is not defined)
  34. and not existing_secret_volume.results.results[0]['items']
  35. register: created_self_signed_cert
  36. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  37. run_once: true
  38. - name: API proxy | Read self signed certificate file
  39. command: cat "{{ mktemp.stdout }}/cert.pem"
  40. register: generated_cert
  41. when: created_self_signed_cert.changed
  42. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  43. run_once: true
  44. - name: API proxy | Read self signed key file
  45. command: cat "{{ mktemp.stdout }}/key.pem"
  46. register: generated_key
  47. when: created_self_signed_cert.changed
  48. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  49. run_once: true
  50. - name: API proxy | Create api-proxy-secrets.yml from template using generated cert
  51. template:
  52. src: api-proxy-secrets.yml.j2
  53. dest: "{{ mktemp.stdout }}/api-proxy-secrets.yml"
  54. vars:
  55. key: "{{ generated_key.stdout }}"
  56. cert: "{{ generated_cert.stdout }}"
  57. when: created_self_signed_cert.changed
  58. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  59. run_once: true
  60. - name: API proxy | Create api-proxy-secrets.yml from template using user defined cert
  61. template:
  62. src: api-proxy-secrets.yml.j2
  63. dest: "{{ mktemp.stdout }}/api-proxy-secrets.yml"
  64. vars:
  65. key: "{{ lookup('file', contiv_api_proxy_key) }}"
  66. cert: "{{ lookup('file', contiv_api_proxy_cert) }}"
  67. when: contiv_api_proxy_cert is defined and contiv_api_proxy_key is defined
  68. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  69. run_once: true
  70. - name: API proxy | Create secret certificate volume
  71. oc_obj:
  72. state: present
  73. namespace: "kube-system"
  74. kind: secret
  75. name: contiv-api-proxy-secret
  76. files:
  77. - "{{ mktemp.stdout }}/api-proxy-secrets.yml"
  78. when: (contiv_api_proxy_cert is defined and contiv_api_proxy_key is defined)
  79. or created_self_signed_cert.changed
  80. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  81. run_once: true
  82. - name: API proxy | Create api-proxy-daemonset.yml from template
  83. template:
  84. src: api-proxy-daemonset.yml.j2
  85. dest: "{{ mktemp.stdout }}/api-proxy-daemonset.yml"
  86. vars:
  87. etcd_host: "etcd://{{ groups.oo_etcd_to_config.0 }}:{{ contiv_etcd_port }}"
  88. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  89. run_once: true
  90. # Always "import" this file, k8s won't do anything if it matches exactly what
  91. # is already in the cluster.
  92. - name: API proxy | Add API proxy daemonset
  93. oc_obj:
  94. state: present
  95. namespace: "kube-system"
  96. kind: daemonset
  97. name: contiv-api-proxy
  98. files:
  99. - "{{ mktemp.stdout }}/api-proxy-daemonset.yml"
  100. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  101. run_once: true
  102. - name: API proxy | Delete temp directory
  103. file:
  104. name: "{{ mktemp.stdout }}"
  105. state: absent
  106. changed_when: False
  107. delegate_to: "{{ groups.oo_masters_to_config.0 }}"
  108. run_once: true