Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2024
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. #cloud-config
  2. autoinstall:
  3. apt:
  4. disable_components: []
  5. fallback: abort
  6. geoip: true
  7. mirror-selection:
  8. primary:
  9. - country-mirror
  10. - arches: &id001
  11. - amd64
  12. - i386
  13. uri: http://archive.ubuntu.com/ubuntu/
  14. - arches: &id002
  15. - s390x
  16. - arm64
  17. - armhf
  18. - powerpc
  19. - ppc64el
  20. - riscv64
  21. uri: http://ports.ubuntu.com/ubuntu-ports
  22. preserve_sources_list: false
  23. security:
  24. - arches: *id001
  25. uri: http://security.ubuntu.com/ubuntu/
  26. - arches: *id002
  27. uri: http://ports.ubuntu.com/ubuntu-ports
  28. codecs:
  29. install: false
  30. drivers:
  31. install: false
  32. interactive-sections:
  33. - network
  34. - identity
  35. identity:
  36. hostname: localhost
  37. password: N/A
  38. realname: tux
  39. username: tux
  40. kernel:
  41. package: linux-generic
  42. keyboard:
  43. layout: us
  44. toggle: null
  45. variant: ''
  46. locale: en_US.UTF-8
  47. oem:
  48. install: auto
  49. source:
  50. id: ubuntu-server
  51. seiarch_drivers: false
  52. ssh:
  53. allow-pw: true
  54. authorized-keys: []
  55. install-server: true
  56. packages:
  57. - curl
  58. - ubuntu-desktop
  59. storage:
  60. config:
  61. # Partition table
  62. - { ptable: gpt, path: /dev/sda, wipe: superblock, preserve: false, name: '', grub_device: false, type: disk, id: disk-sda }
  63. # EFI boot partition
  64. - { device: disk-sda, size: 536870912, wipe: superblock, flag: boot, number: 1, preserve: false, grub_device: true, type: partition, id: partition-0 }
  65. - { fstype: fat32, volume: partition-0, preserve: false, type: format, id: format-0 }
  66. # Linux boot partition
  67. - { device: disk-sda, size: 1073741824, wipe: superblock, flag: '', number: 2, preserve: false, grub_device: false, type: partition, id: partition-1 }
  68. - { fstype: ext4, volume: partition-1, preserve: false, type: format, id: format-1 }
  69. # Partition for LVM, VG
  70. - { device: disk-sda, size: -1, wipe: superblock, flag: '', number: 3, preserve: false, grub_device: false, type: partition, id: partition-2 }
  71. - { name: vgroot, devices: [ partition-2 ], preserve: false, type: lvm_volgroup, id: lvm_volgroup-0 }
  72. # LV for var
  73. - { name: lvvar, volgroup: lvm_volgroup-0, size: 20G, wipe: superblock, preserve: false, type: lvm_partition, id: lvm_partition-0 }
  74. - { fstype: ext4, volume: lvm_partition-0, preserve: false, type: format, id: format-2 }
  75. # LV for root
  76. - { name: lvroot, volgroup: lvm_volgroup-0, size: 10G, wipe: superblock, preserve: false, type: lvm_partition, id: lvm_partition-2 }
  77. - { fstype: ext4, volume: lvm_partition-2, preserve: false, type: format, id: format-4 }
  78. # Mount points
  79. - { path: /boot, device: format-1, type: mount, id: mount-1 }
  80. - { path: /boot/efi, device: format-0, type: mount, id: mount-0 }
  81. - { path: /var, device: format-2, type: mount, id: mount-2 }
  82. - { path: /, device: format-4, type: mount, id: mount-4 }
  83. # Swapfile on root volume
  84. swap:
  85. swap: 5G
  86. updates: all
  87. version: 1
  88. user-data:
  89. write_files:
  90. - path: /etc/rc.local
  91. permissions: "0755"
  92. content: |
  93. #!/bin/bash
  94. # shellcheck disable=SC2181
  95. # --------------------------------------------------------------------------------
  96. # settings
  97. # --------------------------------------------------------------------------------
  98. set -u
  99. # --------------------------------------------------------------------------------
  100. # variables
  101. # --------------------------------------------------------------------------------
  102. webServer="N/A"
  103. webUrl="lxsetup/v1"
  104. bootStrap="bootstrap.sh"
  105. authToken="N/A"
  106. pid="$$"
  107. hostn=$(hostname)
  108. # --------------------------------------------------------------------------------
  109. # functions
  110. # --------------------------------------------------------------------------------
  111. fEcho() {
  112. logger --id ${pid} -t "rc.local" -s -p "local0.info" "$@"
  113. }
  114. # --------------------------------------------------------------------------------
  115. # main
  116. # --------------------------------------------------------------------------------
  117. # don't run, when we are called localhost
  118. #
  119. if [ "${hostn,,}" == "localhost" ]; then
  120. fEcho "WARNING: It seems, that we are still a template, or nobody gave us a name!"
  121. exit 0
  122. fi
  123. if [ ! -f "/etc/machine-id" ]; then
  124. fEcho "INFO: Regenerating machine ID"
  125. /usr/bin/systemd-machine-id-setup
  126. sync
  127. reboot
  128. else
  129. fEcho "INFO: Machine ID is present"
  130. fi
  131. # check that we have network connectivity and can ping the webserver
  132. #
  133. cnt=1
  134. maxRuns="50"
  135. while ! ping -q -c 1 -n -w 1 ${webServer} &>/dev/null; do
  136. fEcho "WARN: Can not reach the infra webserver: ${webServer} -- ${cnt} / ${maxRuns}"
  137. sleep 2
  138. # only go for 50 runs, then get out
  139. #
  140. if [ "${cnt}" -gt "${maxRuns}" ]; then
  141. fEcho "ERROR: stopping rc.local. Tried it now ${maxRuns} times!"
  142. ips=$(ip a)
  143. fEcho "ERROR: IP info: ${ips}"
  144. fEcho "ERROR: Going for a reboot in 5 min"
  145. shutdown -r +5m
  146. exit 1
  147. fi
  148. cnt=$((cnt+=1))
  149. done
  150. fEcho "INFO: reached the infra webserver: ${webServer}"
  151. # now get the bootstrap from our webserver
  152. #
  153. # -s keeps curl quiet by hiding progress meter and error messages
  154. # -S shows an error message if it fails (stderr)
  155. # -f Fail silently (no output at all) on server errors, keeping stdout clean
  156. # -o specifies an output file
  157. # -k unkown ssl-cert is ok
  158. # -H send header information
  159. #
  160. curl -s -S -f -k -H "Authorization: Basic ${authToken}" -o /tmp/${bootStrap} [https://$%7bwebServer%7d/$%7bwebUrl%7d/$%7bbootStrap%7d]https://${webServer}/${webUrl}/${bootStrap}
  161. if [ "$?" -ne 0 ]; then
  162. fEcho "ERROR: Could not download the bootstrap file from ${webServer}"
  163. exit 1
  164. fi
  165. bash /tmp/${bootStrap}
  166. if [ "$?" -ne 0 ]; then
  167. fEcho "ERROR: Could not install puppet"
  168. exit 1
  169. fi
  170. rm /tmp/${bootStrap}
  171. if [ -f /etc/rc.local ]; then
  172. fEcho "INFO: Removing /etc/rc.local"
  173. rm /etc/rc.local
  174. fi
  175. sync
  176. sync
  177. fEcho "INFO: Everything went good, going for a reboot"
  178. sleep 1
  179. reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement