Advertisement
yudjinDegtyarev

Untitled

Nov 14th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. # a build block invokes sources and runs provisioning steps on them. The
  2. # documentation for build blocks can be found here:
  3. # https://www.packer.io/docs/templates/hcl_templates/blocks/build
  4. build {
  5. sources = ["source.vsphere-iso.lab-test"]
  6.  
  7. # Get node ip, send it to VM_IP_ADD var.
  8. provisioner "shell" {
  9. inline = [
  10. "export VM_IP_ADD=$(echo $SSH_CONNECTION | cut -f3 -d' ')",
  11. "env | grep VM_IP >> /tmp/shared.vars"
  12. ]
  13. }
  14.  
  15. # Update node, install docker
  16. provisioner "shell" {
  17. inline = [
  18. "sudo apt-get -y update",
  19. "sudo apt install -y docker.io docker-compose htop vim curl sqlite3"
  20. ]
  21. }
  22.  
  23. # Copy scripts for tower install
  24. provisioner "file" {
  25. sources = ["scripts/install_tower.sh","scripts/fullfill_db.tmpl","scripts/make_sql.sh"]
  26. destination = "/tmp/"
  27. }
  28.  
  29. # Run installation script
  30. provisioner "shell" {
  31. execute_command = "sudo env {{ .Vars }} {{ .Path }}"
  32. environment_vars = [
  33. "CI_PROXY=${var.PROXY}"
  34. ]
  35. }
  36. # Fill tower
  37. provisioner "shell" {
  38. execute_command = "sudo env {{ .Vars }} {{ .Path }}"
  39. environment_vars = [
  40. "CI_PROXY=${var.PROXY}"
  41. ]
  42. }
  43. # Run installation script
  44. provisioner "shell" {
  45. inline = ["chmod +x /tmp/install_tower.sh","sudo /tmp/install_tower.sh"]
  46. }
  47.  
  48. # Fill tower
  49. provisioner "shell" {
  50. inline = ["chmod +x /tmp/make_sql.sh","sudo /tmp/make_sql.sh"]
  51. }
  52.  
  53. # Pull deploy playbooks
  54. provisioner "shell" {
  55. inline = ["sudo docker ps","sudo docker exec -t tower_tower_1 tower-pull"]
  56. }
  57.  
  58. # Generate tower.yml file
  59. provisioner "shell" {
  60. inline = ["sudo docker ps","sudo docker exec -t tower_tower_1 tower-deploy --generate"]
  61. }
  62.  
  63. # Deploy
  64. provisioner "shell" {
  65. inline = ["sudo docker exec -t tower_tower_1 ansible-playbook -i bin/tower-inv /opt/tower/var/tower/playbooks/NOC/site.yml --extra-vars 'tower_show_secrets=false'" ]
  66. }
  67.  
  68. # Info msg
  69. provisioner "shell" {
  70. inline = ["echo 'Deploy is completed'"]
  71. }
  72.  
  73. # Some cleaning
  74. provisioner "shell" {
  75. inline = ["sudo sqlite3 /opt/tower/var/tower/db/config.db < /tmp/clean_tower.sql"]
  76. }
  77.  
  78. provisioner "shell" {
  79. execute_command = "sudo env {{ .Vars }} {{ .Path }}"
  80. inline = [
  81. <<-SCRIPT
  82.  
  83. passwd --expire root
  84.  
  85. SCRIPT
  86. ]
  87. }
  88.  
  89. # Info msg
  90. provisioner "shell" {
  91. inline = ["echo 'Cleaning is completed'"]
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement