node_docker_ca.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ---
  2. - name: Configure CA certificate for secure registry
  3. hosts: oo_nodes_to_config
  4. tags:
  5. - hosted
  6. tasks:
  7. - name: Create temp directory for kubeconfig
  8. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  9. register: mktemp
  10. when: openshift_hosted_manage_registry | default(true) | bool
  11. changed_when: false
  12. delegate_to: "{{ groups.oo_first_master.0 }}"
  13. run_once: true
  14. - set_fact:
  15. openshift_hosted_kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
  16. when: openshift_hosted_manage_registry | default(true) | bool
  17. delegate_to: "{{ groups.oo_first_master.0 }}"
  18. run_once: true
  19. - name: Copy the admin client config(s)
  20. command: >
  21. cp {{ openshift.common.config_base }}/master/admin.kubeconfig {{ openshift_hosted_kubeconfig }}
  22. when: openshift_hosted_manage_registry | default(true) | bool
  23. changed_when: false
  24. delegate_to: "{{ groups.oo_first_master.0 }}"
  25. run_once: true
  26. - name: Retrieve docker-registry route
  27. command: >
  28. {{ openshift.common.client_binary }} get route docker-registry
  29. -o jsonpath='{.spec.host}'
  30. --config={{ openshift_hosted_kubeconfig }}
  31. -n default
  32. register: docker_registry_route
  33. when: openshift_hosted_manage_registry | default(true) | bool
  34. changed_when: false
  35. delegate_to: "{{ groups.oo_first_master.0 }}"
  36. run_once: true
  37. - name: Retrieve registry service IP
  38. command: >
  39. {{ openshift.common.client_binary }} get svc/docker-registry
  40. -o jsonpath='{.spec.clusterIP}'
  41. --config={{ openshift_hosted_kubeconfig }}
  42. -n default
  43. register: docker_registry_service_ip
  44. when: openshift_hosted_manage_registry | default(true) | bool
  45. changed_when: false
  46. delegate_to: "{{ groups.oo_first_master.0 }}"
  47. run_once: true
  48. - name: Create registry CA directories
  49. file:
  50. path: "/etc/docker/certs.d/{{ item }}"
  51. state: directory
  52. with_items:
  53. - "{{ docker_registry_service_ip.stdout }}:5000"
  54. - "{{ docker_registry_route.stdout }}"
  55. - "docker-registry.default.svc.cluster.local:5000"
  56. when: openshift_hosted_manage_registry | default(true) | bool
  57. - name: Copy CA to registry CA directories
  58. copy:
  59. src: "{{ openshift.common.config_base }}/node/ca.crt"
  60. dest: "/etc/docker/certs.d/{{ item }}"
  61. remote_src: yes
  62. force: yes
  63. with_items:
  64. - "{{ docker_registry_service_ip.stdout }}:5000"
  65. - "{{ docker_registry_route.stdout }}"
  66. - "docker-registry.default.svc.cluster.local:5000"
  67. when: openshift_hosted_manage_registry | default(true) | bool
  68. notify:
  69. - Wait for docker-registry deployment
  70. - Wait for registry-console deployment
  71. - Restart docker
  72. handlers:
  73. # Restarting docker before deployments have begun will block the
  74. # deployments from ever starting so try waiting for the registry to
  75. # become available.
  76. - name: Wait for docker-registry deployment
  77. command: >
  78. {{ openshift.common.client_binary }} get dc/docker-registry
  79. -o jsonpath='{.status.availableReplicas}'
  80. --config={{ openshift_hosted_kubeconfig }}
  81. -n default
  82. delegate_to: "{{ groups.oo_first_master.0}}"
  83. register: l_docker_registry_available_replicas
  84. until: l_docker_registry_available_replicas.stdout | default("0") != "0"
  85. retries: 30
  86. delay: 1
  87. failed_when: false
  88. changed_when: false
  89. run_once: true
  90. - name: Wait for registry-console deployment
  91. command: >
  92. {{ openshift.common.client_binary }} get dc/registry-console
  93. -o jsonpath='{.status.availableReplicas}'
  94. --config={{ openshift_hosted_kubeconfig }}
  95. -n default
  96. delegate_to: "{{ groups.oo_first_master.0 }}"
  97. register: l_registry_console_available_replicas
  98. until: l_registry_console_available_replicas.stdout | default("0") != "0"
  99. retries: 30
  100. delay: 1
  101. failed_when: false
  102. changed_when: false
  103. run_once: true
  104. - name: Restart docker
  105. service:
  106. name: docker
  107. state: restarted
  108. - name: Delete temp directory
  109. hosts: oo_first_master
  110. tags:
  111. - hosted
  112. tasks:
  113. - name: Delete temp directory
  114. file:
  115. name: "{{ mktemp.stdout }}"
  116. state: absent
  117. when: openshift_hosted_manage_registry | default(true) | bool
  118. changed_when: False