Advertisement
Guest User

Untitled

a guest
Mar 7th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 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. # Slicing the hostname
  12. {% if host_items_count == 2 %}
  13. {% set component = host_list[0] %}
  14. {% set role = '' %}
  15. {% set host_id = host_list[1] %}
  16. {% set host_combo = host_list[0] %}
  17. {% elif host_items_count == 3 %}
  18. {% set component = host_list[0] %}
  19. {% set cluster = host_list[1] %}
  20. {% set role = '' %}
  21. {% set host_id = host_list[2] %}
  22. {% set host_combo = host_list[0] + '-' + host_list[1] %}
  23. {% elif host_items_count == 4 %}
  24. {% set component = host_list[0] %}
  25. {% set cluster = host_list[1] %}
  26. {% set role = host_list[2] %}
  27. {% set host_id = host_list[3] %}
  28. {% set host_combo = host_list[0] + '-' + host_list[1] + '-' + host_list[2] %}
  29. {% elif host_items_count == 5 %}
  30. {% set component = host_list[0] %}
  31. {% set cluster = host_list[1] %}
  32. {% set role = host_list[2] %}
  33. {% set codename = host_list[3] %}
  34. {% set host_id = host_list[4] %}
  35. {% set host_combo = host_list[0] + '-' + host_list[1] + '-' + host_list[2] %}
  36. {% endif %}
  37.  
  38. # Slicing the domain
  39. {% set domain_items_count = domain_list|length %}
  40.  
  41. {% if domain_items_count >= 5 %}
  42. {% set env = domain_list[0] %}
  43. {% set region = domain_list[1] %}
  44. {% set provider = domain_list[2] %}
  45. {% set root_domain = ".".join(domain_list[3:]) %}
  46. {% endif %}
  47.  
  48. {% if root_domain == 'fetchcore-developers.com' %}
  49. {% set account = 'development' %}
  50. {% elif root_domain == 'fetchcore-cloud.com' %}
  51. {% set account = 'production' %}
  52. {% endif %}
  53.  
  54. # Additional combinations
  55. {% set component_cluster = component + '-' + cluster %}
  56. {% set component_role = component + '-' + role %}
  57. {% set component_cluster_role = component + '-' + cluster + '-' + role %}
  58. {% set component_cluster_env = component + '-' + cluster + '-' + env %}
  59. {% set component_cluster_env_region = component + '-' + cluster + '-' + env + '-' + region %}
  60. {% set cluster_env_region = cluster + '-' + env + '-' + region %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement