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.

38 lines
889B

  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. linux_host_{{ name }}:
  6. host.present:
  7. - ip: {{ host.address }}
  8. - names: {{ host.names }}
  9. {%- if host.address in grains.ipv4 and host.names|length > 1 %}
  10. {%- if host.names.1 in host.names.0 %}
  11. {%- set before = host.names.1 + " " + host.names.0 %}
  12. {%- set after = host.names.0 + " " + host.names.1 %}
  13. {%- elif host.names.0 in host.names.1 %}
  14. {%- set before = host.names.0 + " " + host.names.1 %}
  15. {%- set after = host.names.1 + " " + host.names.0 %}
  16. {%- endif %}
  17. linux_host_{{ name }}_order_fix:
  18. module.run:
  19. - name: file.replace
  20. - path: /etc/hosts
  21. - pattern: {{ before }}
  22. - repl: {{ after }}
  23. - watch:
  24. - host: linux_host_{{ name }}
  25. {%- endif %}
  26. {%- endif %}
  27. {%- endfor %}
  28. {%- endif %}