Saltstack Official Linux Formula
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

host.sls 2.2KB

il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 9 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {%- from "linux/map.jinja" import network with context %}
  2. {%- if network.enabled %}
  3. {%- set host_dict = network.host %}
  4. {%- if network.mine_dns_records %}
  5. {%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
  6. {%- if node_grains.get('dns_records', []) is iterable %}
  7. {%- for record in node_grains.get('dns_records', []) %}
  8. {%- set record_key = node_name ~ '-' ~ loop.index %}
  9. {%- do host_dict.update({ record_key: {'address': record.address, 'names': record.names} }) %}
  10. {%- endfor %}
  11. {%- endif %}
  12. {%- endfor %}
  13. {%- endif %}
  14. {%- if network.get('purge_hosts', false) %}
  15. linux_hosts:
  16. file.managed:
  17. - name: /etc/hosts
  18. - source: salt://linux/files/hosts
  19. - template: jinja
  20. - defaults:
  21. host_dict: {{ host_dict|yaml }}
  22. {%- else %}
  23. {%- for name, host in host_dict.iteritems() %}
  24. {%- if host.names is defined %}
  25. {%- set clearers = [] %}
  26. {%- for etc_addr, etc_names in salt.hosts.list_hosts().iteritems() %}
  27. {%- set names_to_clear = [] %}
  28. {%- for host_name in host.names %}
  29. {%- if (host.address != etc_addr) and host_name in etc_names %}
  30. {%- do names_to_clear.append(host_name) %}
  31. {%- endif %}
  32. {%- endfor %}
  33. {%- if names_to_clear != [] %}
  34. {%- set clearer = "linux_host_" + name + "_" + etc_addr + "_clear" %}
  35. {%- do clearers.append(clearer) %}
  36. {{ clearer }}:
  37. host.absent:
  38. - ip: {{ etc_addr }}
  39. - names: {{ names_to_clear }}
  40. {%- endif %}
  41. {%- endfor %}
  42. linux_host_{{ name }}:
  43. host.present:
  44. - ip: {{ host.address }}
  45. - names: {{ host.names }}
  46. - require: {{ clearers }}
  47. {%- if host.address in grains.ipv4 and host.names|length > 1 %}
  48. {%- if host.names.1 in host.names.0 %}
  49. {%- set before = host.names.1 + " " + host.names.0 %}
  50. {%- set after = host.names.0 + " " + host.names.1 %}
  51. {%- elif host.names.0 in host.names.1 %}
  52. {%- set before = host.names.0 + " " + host.names.1 %}
  53. {%- set after = host.names.1 + " " + host.names.0 %}
  54. {%- endif %}
  55. linux_host_{{ name }}_order_fix:
  56. module.run:
  57. - name: file.replace
  58. - path: /etc/hosts
  59. - pattern: {{ before }}
  60. - repl: {{ after }}
  61. - watch:
  62. - host: linux_host_{{ name }}
  63. - onlyif:
  64. - grep -q "{{ before }}" /etc/hosts
  65. {%- endif %}
  66. {%- endif %}
  67. {%- endfor %}
  68. {%- endif %}
  69. {%- endif %}