apply_machine_config.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ---
  2. - name: Create temp directory
  3. tempfile:
  4. state: directory
  5. register: temp_dir
  6. - name: Get worker machine current config name
  7. command: >
  8. oc get node {{ ansible_nodename | lower }}
  9. --kubeconfig={{ openshift_node_kubeconfig_path }}
  10. --output=jsonpath='{.metadata.annotations.machineconfiguration\.openshift\.io/desiredConfig}'
  11. delegate_to: localhost
  12. register: oc_get
  13. until:
  14. - oc_get.stdout != ''
  15. retries: 36
  16. delay: 5
  17. - name: Set l_worker_machine_config_name
  18. set_fact:
  19. l_worker_machine_config_name: "{{ oc_get.stdout }}"
  20. - name: Get worker ignition config
  21. command: >
  22. oc get machineconfig {{ l_worker_machine_config_name }}
  23. --kubeconfig={{ openshift_node_kubeconfig_path }}
  24. --output=json
  25. delegate_to: localhost
  26. register: oc_get
  27. until:
  28. - oc_get.stdout != ''
  29. retries: 36
  30. delay: 5
  31. - name: Write worker ignition config to file
  32. copy:
  33. content: "{{ (oc_get.stdout | from_json).spec.config }}"
  34. dest: "{{ temp_dir.path }}/worker_ignition_config.json"
  35. - name: Get machine-config-operator image
  36. command: >
  37. oc get daemonset machine-config-daemon
  38. --kubeconfig={{ openshift_node_kubeconfig_path }}
  39. --namespace=openshift-machine-config-operator
  40. --output=jsonpath='{.spec.template.spec.containers[?(@.name=="machine-config-daemon")].image}'
  41. delegate_to: localhost
  42. register: oc_get
  43. until:
  44. - oc_get.stdout != ''
  45. retries: 36
  46. delay: 5
  47. - name: Set l_mcd_image fact
  48. set_fact:
  49. l_mcd_image: "{{ oc_get.stdout }}"
  50. - import_tasks: proxy.yml
  51. - block:
  52. - name: Pull MCD image
  53. command: "podman pull --tls-verify={{ openshift_node_tls_verify }} --authfile /var/lib/kubelet/config.json {{ l_mcd_image }}"
  54. register: podman_pull
  55. until:
  56. podman_pull.stdout != ''
  57. retries: 12
  58. delay: 10
  59. - name: Apply machine config
  60. command: "podman run {{ podman_mounts }} {{ podman_flags }} {{ mcd_command }}"
  61. vars:
  62. podman_flags: "--privileged --rm --entrypoint=/usr/bin/machine-config-daemon -ti {{ l_mcd_image }}"
  63. podman_mounts: "-v /:/rootfs -v /var/run/dbus:/var/run/dbus -v /run/systemd:/run/systemd"
  64. mcd_command: "start --node-name {{ ansible_nodename | lower }} --once-from {{ temp_dir.path }}/worker_ignition_config.json --skip-reboot"
  65. environment:
  66. http_proxy: "{{ http_proxy | default('')}}"
  67. https_proxy: "{{https_proxy | default('')}}"
  68. no_proxy: "{{ no_proxy | default('')}}"
  69. - name: Remove temp directory
  70. file:
  71. path: "{{ temp_dir.path }}"
  72. state: absent
  73. - name: Reboot the host and wait for it to come back
  74. reboot:
  75. # reboot_timeout: 600 # default, 10 minutes
  76. - block:
  77. - name: Wait for node to report ready
  78. command: >
  79. oc get node {{ ansible_nodename | lower }}
  80. --kubeconfig={{ openshift_node_kubeconfig_path }}
  81. --output=jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
  82. delegate_to: localhost
  83. register: oc_get
  84. until:
  85. - oc_get.stdout == "True"
  86. retries: 36
  87. delay: 5
  88. changed_when: false
  89. rescue:
  90. - import_tasks: gather_debug.yml
  91. - name: DEBUG - Node failed to report ready
  92. fail:
  93. msg: "Node failed to report ready"