Saltstack Official Linux Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.7KB

  1. {# Macro, put quotation marks around strings that are not ipv4 address #}
  2. {%- macro quote_if_not_ip(var) -%}
  3. {%- set var_split_str = var.split(".") -%}
  4. {%- if var_split_str|length == 4 -%}
  5. {%- set var_is_ipaddr = True -%}
  6. {%- for octet in var_split_str -%}
  7. {%- if not octet|int in range(255) -%}
  8. {%- set var_is_ipaddr = False -%}
  9. {%- endif -%}
  10. {%- endfor -%}
  11. {%- endif -%}
  12. {%- if var_is_ipaddr is defined and var_is_ipaddr == True -%}
  13. {{ var }}
  14. {%- else -%}
  15. "{{ var }}"
  16. {%- endif -%}
  17. {%- endmacro -%}
  18. {# Macro, renders nested options for specific key #}
  19. {%- macro render_key(section, key) -%}
  20. {%- if section.get(key) and section.get(key)|length > 0 %}
  21. {%- for item in section.get(key) %}
  22. {%- if item.declaration is string %}
  23. {{ key }} {{ item.option }} {{ quote_if_not_ip(item.declaration) }};
  24. {%- elif item.declaration is sequence %}
  25. {{ key }} {{ item.option }}
  26. {%- for value in item.declaration -%}
  27. {%- set space = " " -%}
  28. {{ space }}{{ quote_if_not_ip(value) }}
  29. {%- if not loop.last -%},{%- endif -%}
  30. {%- endfor -%}
  31. ;
  32. {%- else %}
  33. {{ key }} {{ item.option }} {{ item.declaration }};
  34. {%- endif -%}
  35. {%- endfor -%}
  36. {%- endif -%}
  37. {%- endmacro -%}
  38. {# Macro, renders set of options for global section or for interface section #}
  39. {%- macro render_section(section) -%}
  40. {%- if section.backoff_cutoff is defined %}
  41. backoff-cutoff {{ section.backoff_cutoff|default(15, true) }};
  42. {%- endif -%}
  43. {%- if section.initial_interval is defined %}
  44. initial-interval {{ section.initial_interval|default(10, true) }};
  45. {%- endif -%}
  46. {%- if section.reboot is defined %}
  47. # The reboot statement sets the time that must elapse after the client
  48. # first tries to reacquire its old address before it gives up and tries
  49. # to discover a new address.
  50. reboot {{ section.reboot|default(10, true) }};
  51. {%- endif -%}
  52. {%- if section.retry is defined %}
  53. retry {{ section.retry|default(60, true) }};
  54. {%- endif -%}
  55. {%- if section.select_timeout is defined %}
  56. # The select-timeout is the time after the client sends its first lease
  57. # discovery request at which it stops waiting for offers from servers,
  58. # assuming that it has received at least one such offer
  59. select-timeout {{ section.select_timeout|default(0, True) }};
  60. {%- endif -%}
  61. {%- if section.timeout is defined %}
  62. timeout {{ section.timeout|default(120, True) }};
  63. {%- endif -%}
  64. {{ render_key(section, "send") }}
  65. {{ render_key(section, "supersede") }}
  66. {{ render_key(section, "prepend") }}
  67. {{ render_key(section, "append") }}
  68. {%- if section.reject is defined and section.reject|length > 0 %}
  69. reject {{ section.reject|join(",\n ") }};
  70. {%- endif %}
  71. {%- if section.request is defined and section.request|length > 0 %}
  72. request {{ section.request|join(",\n ") }};
  73. {%- endif %}
  74. {%- if section.require is defined and section.require|length > 0 %}
  75. require {{ section.require|join(",\n ") }};
  76. {% endif -%}
  77. {%- endmacro -%}
  78. {# Actual template start #}
  79. {%- from "linux/map.jinja" import network with context -%}
  80. {%- set dhclient = network.get('dhclient', {}) %}
  81. # dhclient.conf(5) file managed by salt-minion(1)
  82. # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
  83. option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
  84. {{ render_section(dhclient) }}
  85. {%- if dhclient.get("interface") -%}
  86. {%- for iface_name, options in dhclient.interface.items() %}
  87. {%- if network.interface.get(iface_name) and network.interface.get(iface_name).enabled == True
  88. and network.interface.get(iface_name).proto == 'dhcp' -%}
  89. interface "{{ iface_name }}" {
  90. {{ render_section(options)|indent }}
  91. }
  92. {%- endif -%}
  93. {%- endfor %}
  94. {%- endif -%}