stejzyy23

Global reg. template POC

Jul 10th, 2020
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.40 KB | None | 0 0
  1. <%#
  2. kind: registration
  3. name: Global registration default
  4. model: ProvisioningTemplate
  5. oses:
  6. - RHEL
  7. -%>
  8.  
  9. #!/bin/bash
  10. # curl --insecure <%= foreman_server_url %>/unattended/build_default_registration | bash
  11. <%
  12.   admin = "admin"
  13.   password = "changeme"
  14.   organization = "Default_Organization"
  15.   activation_key = "key1"
  16.  
  17.   curl_opts = ["-X GET", "--silent", "-H 'Content-Type: application/json'", "-H 'Accept: application/json'", "--user #{admin}:#{password}"]
  18. %>
  19.  
  20. if (( $EUID != 0 )); then
  21.     echo "Please run as root"
  22.     exit 1
  23. fi
  24.  
  25. # Host Registration to Satellite
  26. curl --insecure --force --output katello-ca-consumer-latest.noarch.rpm <%= foreman_server_url %>/pub/katello-ca-consumer-latest.noarch.rpm
  27. yum localinstall katello-ca-consumer-latest.noarch.rpm -y
  28. subscription-manager register --org=<%= organization %> --activationkey=<%= activation_key %>
  29.  
  30. subscription-manager identity
  31. SUB_UUID=$(subscription-manager identity | grep "^system identity" | awk '{print $3}')
  32. HOST_ID=$(curl <%= curl_opts.join(' ') %> -d "{\"search\":\"subscription_uuid = $SUB_UUID\"}" "<%= foreman_server_url %>/api/hosts" | grep -Po '(?<=\"id\":)\d+' | head -1)
  33.  
  34. echo ""
  35. echo "FOREMAN HOST ID: ${HOST_ID}"
  36. echo "Run registration template:"
  37. echo "curl <%= curl_opts.join(" ") %> \\"
  38. echo "  <%= foreman_server_url %>/api/hosts/$HOST_ID/template/registration | grep -Po '(?<=\"template\":)(.*)(?=\"})' | bash"
Add Comment
Please, Sign In to add comment