build_node_image.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ---
  2. - hosts: localhost
  3. gather_facts: no
  4. tasks:
  5. - name: calculate input image
  6. command: az image list -g "{{ openshift_azure_input_image_ns }}" --query "[?starts_with(name, '{{ openshift_azure_input_image_prefix }}-') && tags.valid=='true'] | sort_by(@, &name) | [-1]"
  7. register: input_image
  8. - name: provision resource group
  9. import_tasks: tasks/provision_instance.yml
  10. vars:
  11. create_args: --data-disk-sizes-gb 128
  12. - hosts: nodes
  13. tasks:
  14. - set_fact:
  15. openshift_deployment_type: "{{ 'openshift-enterprise' if ansible_distribution == 'RedHat' else 'origin' }}"
  16. openshift_enable_origin_repo: False
  17. skip_node_svc_handlers: True
  18. openshift_additional_repos: "{{ azure_node_repos[ansible_distribution] }}"
  19. openshift_node_include_control_plane: True
  20. openshift_control_plane_static_pod_location: /etc/origin/node/disabled/
  21. openshift_node_group_cloud_provider: azure
  22. openshift_node_image_prep_packages:
  23. - strace
  24. - tcpdump
  25. etcd_ip: ETCD_IP_REPLACE
  26. - name: add insights-client to package installs when on rhel
  27. set_fact:
  28. openshift_node_image_prep_packages: "{{ openshift_node_image_prep_packages | union(['insights-client']) }}"
  29. when: openshift_deployment_type == 'openshift-enterprise'
  30. - set_fact:
  31. openshift_additional_repos: "{{ openshift_additional_repos + [{'name': 'install_repo', 'baseurl': openshift_azure_install_repo, 'enabled': true, 'gpgcheck': false}] }}"
  32. when: openshift_azure_install_repo is defined and openshift_azure_install_repo
  33. - name: install centos-release-paas-common rpm
  34. yum:
  35. name: centos-release-paas-common
  36. state: present
  37. when: ansible_distribution == "CentOS"
  38. - name: configure yum repositories
  39. import_tasks: tasks/yum_certs.yml
  40. - name: update rpms
  41. import_role:
  42. name: os_update_latest
  43. vars:
  44. os_update_latest_reboot: True
  45. - name: install openshift
  46. import_playbook: ../../openshift-node/private/image_prep.yml
  47. vars:
  48. etcd_image: "{{ etcd_image_dict[openshift_deployment_type] }}"
  49. - hosts: nodes
  50. tasks:
  51. - name: deconfigure yum repositories
  52. import_tasks: tasks/remove_yum.yml
  53. - name: add get-node-logs script
  54. copy:
  55. src: files/get-node-logs
  56. dest: /usr/local/bin/get-node-logs
  57. owner: root
  58. group: root
  59. mode: 0755
  60. - name: record installed rpms
  61. yum:
  62. list: installed
  63. register: yum
  64. - name: disable waagent data disk management
  65. lineinfile:
  66. path: /etc/waagent.conf
  67. regexp: "{{ item.regexp }}"
  68. line: "{{ item.line }}"
  69. with_items:
  70. - { regexp: '^ResourceDisk\.Format=', line: 'ResourceDisk.Format=n' }
  71. - name: persist oreg_url
  72. copy:
  73. dest: "/etc/origin/oreg_url"
  74. content: "{{ oreg_url }}"
  75. when: oreg_url is defined
  76. - name: create a file with image name
  77. copy:
  78. content: |
  79. ---
  80. image_name: {{ openshift_azure_output_image_name }}
  81. base_image: {{ (hostvars['localhost'].input_image.stdout | from_json).name }}
  82. subscription: {{ lookup('env', 'AZURE_SUBSCRIPTION_ID') }}
  83. resource_group: {{ openshift_azure_output_image_ns }}
  84. dest: /etc/origin/image.yml
  85. owner: root
  86. group: root
  87. mode: '0440'
  88. - name: run waagent deprovision
  89. shell: sleep 2 && waagent -deprovision+user -force
  90. async: 1
  91. poll: 0
  92. - hosts: localhost
  93. gather_facts: no
  94. tasks:
  95. - set_fact:
  96. openshift_rpm: "{{ hostvars[groups['nodes'][0]]['yum'].results | selectattr('name', 'match', '^(origin-hyperkube|atomic-openshift-hyperkube)$') | first }}"
  97. - name: create image
  98. import_tasks: tasks/create_image_from_vm.yml
  99. vars:
  100. image_resource_group: "{{ openshift_azure_output_image_ns }}"
  101. image_name: "{{ openshift_azure_output_image_name }}"
  102. image_tags:
  103. base_image: "{{ (input_image.stdout | from_json).name }}"
  104. kernel: "{{ hostvars[groups['nodes'][0]]['ansible_kernel'] }}"
  105. openshift: "{{ openshift_rpm.version }}-{{ openshift_rpm.release }}.{{ openshift_rpm.arch }}"
  106. - name: create blob
  107. import_tasks: tasks/create_blob_from_vm.yml
  108. vars:
  109. image_name: "{{ openshift_azure_output_image_name }}"
  110. when: openshift_azure_storage_account is defined and openshift_azure_storage_account