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.

52 satır
1.1KB

  1. {%- from "linux/map.jinja" import network with context %}
  2. {%- if network.enabled %}
  3. {%- for name, host in network.host.iteritems() %}
  4. {%- if host.names is defined %}
  5. {%- if host.get('enabled', True) %}
  6. linux_host_{{ name }}:
  7. host.present:
  8. - ip: {{ host.address }}
  9. - names: {{ host.names }}
  10. {%- if host.address in grains.ipv4 and host.names|length > 1 %}
  11. {%- if host.names.1 in host.names.0 %}
  12. {%- set before = host.names.1 + " " + host.names.0 %}
  13. {%- set after = host.names.0 + " " + host.names.1 %}
  14. {%- elif host.names.0 in host.names.1 %}
  15. {%- set before = host.names.0 + " " + host.names.1 %}
  16. {%- set after = host.names.1 + " " + host.names.0 %}
  17. {%- endif %}
  18. linux_host_{{ name }}_order_fix:
  19. module.run:
  20. - name: file.replace
  21. - path: /etc/hosts
  22. - pattern: {{ before }}
  23. - repl: {{ after }}
  24. - watch:
  25. - host: linux_host_{{ name }}
  26. - onlyif:
  27. - grep -q "{{ before }}" /etc/hosts
  28. {%- endif %}
  29. {%- else %}
  30. linux_host_{{ name }}_absent:
  31. host.absent:
  32. - ip: {{ host.address }}
  33. - names: {{ host.names }}
  34. {%- endif %}
  35. {%- endif %}
  36. {%- endfor %}
  37. {%- endif %}