Advertisement
Guest User

Untitled

a guest
Mar 30th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. # Using the hard coded from the salt-key name grain, grains['id'], for security
  2. {% set host_text, domain_text = salt['grains.get']('id').partition('.')[::2] %}
  3.  
  4. {% set subdomain = salt['grains.get']('id').partition('.')[2].partition('.')[2] %}
  5.  
  6. {% set host_list = host_text.split("-") %}
  7. {% set domain_list = domain_text.split(".") %}
  8.  
  9. {% set host_items_count = host_list|length %}
  10.  
  11. {% set tld = domain_list[-1] %}
  12. {% if tld == 'com' or tld == 'com' or tld == 'org' %}
  13. {% set root_domain = ".".join(domain_list[3:]) %}
  14. {% else %}
  15. {% set root_domain = ".".join(domain_list[2:]) %}
  16. {% endif %}
  17.  
  18. {% set subnet = salt['grains.get']('subnet_short') %}
  19.  
  20. # Slicing the hostname
  21. {% if host_items_count == 2 %}
  22. {% set component = host_list[0] %}
  23. {% set cluster = '' %}
  24. {% set role = '' %}
  25. {% set host_id = host_list[1] %}
  26. {% set host_combo = host_list[0] %}
  27. {% elif host_items_count == 3 %}
  28. {% set component = host_list[0] %}
  29. {% set cluster = host_list[1] %}
  30. {% set role = '' %}
  31. {% set host_id = host_list[2] %}
  32. {% set host_combo = host_list[0] + '-' + host_list[1] %}
  33. {% elif host_items_count == 4 %}
  34. {% set component = host_list[0] %}
  35. {% set cluster = host_list[1] %}
  36. {% set role = host_list[2] %}
  37. {% set host_id = host_list[3] %}
  38. {% set host_combo = host_list[0] + '-' + host_list[1] + '-' + host_list[2] %}
  39. {% elif host_items_count == 5 %}
  40. {% set component = host_list[0] %}
  41. {% set cluster = host_list[1] %}
  42. {% set role = host_list[2] %}
  43. {% set codename = host_list[3] %}
  44. {% set host_id = host_list[4] %}
  45. {% set host_combo = host_list[0] + '-' + host_list[1] + '-' + host_list[2] %}
  46. {% endif %}
  47.  
  48. # Slicing the domain
  49. {% set domain_items_count = domain_list|length %}
  50.  
  51. {% if domain_items_count >= 5 %}
  52. {% set env = domain_list[0] %}
  53. {% set region = domain_list[1] %}
  54. {% set provider = domain_list[2] %}
  55. {% endif %}
  56.  
  57. # Additional combinations
  58. {% set component_cluster = component + '-' + cluster %}
  59. {% set component_role = component + '-' + role %}
  60. {% set component_cluster_role = component + '-' + cluster + '-' + role %}
  61. {% set component_cluster_env = component + '-' + cluster + '-' + env %}
  62. {% set component_cluster_env_region = component + '-' + cluster + '-' + env + '-' + region %}
  63. {% set cluster_env_region = cluster + '-' + env + '-' + region %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement