Advertisement
Guest User

Untitled

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