Saltstack Official Home Assistant 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.

server.sls 2.9KB

8 anni fa
8 anni fa
7 anni fa
7 anni fa
7 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {%- from "home_assistant/map.jinja" import server with context %}
  2. {%- if server.enabled %}
  3. home_assistant_packages:
  4. pkg.installed:
  5. - names: {{ server.pkgs }}
  6. home_assistant_user:
  7. user.present:
  8. - name: home_assistant
  9. - system: true
  10. - home: {{ server.dir.base }}
  11. {{ server.dir.base }}:
  12. virtualenv.manage:
  13. - user: home_assistant
  14. - system_site_packages: True
  15. - requirements: salt://home_assistant/files/requirements.txt
  16. - python: /usr/bin/python3
  17. - require:
  18. - pkg: home_assistant_packages
  19. - user: home_assistant_user
  20. home_assistant_install:
  21. pip.installed:
  22. {%- if server.source is defined and server.source.get("engine", "git") %}
  23. - editable: git+{{ server.source.address }}@{{ server.source.version }}#egg=homeassistant
  24. {%- else %}
  25. - name: homeassistant{%- if server.get('source', {}).version is defined %}=={{ server.source.version }}{%- endif %}
  26. {%- endif %}
  27. - user: home_assistant
  28. - pre_releases: True
  29. - bin_env: {{ server.dir.base }}
  30. - exists_action: w
  31. - require:
  32. - virtualenv: {{ server.dir.base }}
  33. - pkg: home_assistant_packages
  34. home_assistant_dir:
  35. file.directory:
  36. - names:
  37. - /etc/home_assistant
  38. - /var/log/home_assistant
  39. - mode: 700
  40. - makedirs: true
  41. - user: home_assistant
  42. - require:
  43. - virtualenv: {{ server.dir.base }}
  44. {%- if server.config.engine == 'git' %}
  45. home_assistant_config:
  46. git.latest:
  47. - name: {{ server.config.address }}
  48. - user: home_assistant
  49. - target: /etc/home_assistant
  50. - rev: {{ server.config.revision|default(server.config.branch) }}
  51. {%- if grains.saltversion >= "2015.8.0" %}
  52. - branch: {{ server.config.branch|default(server.config.revision) }}
  53. {%- endif %}
  54. {%- if server.config.identity is defined %}
  55. - identity: {{ server.config.identity }}
  56. {%- endif %}
  57. - force_reset: {{ server.config.force_reset|default(False) }}
  58. {%- else %}
  59. home_assistant_config:
  60. file.managed:
  61. - name: /etc/home_assistant/configuration.yaml
  62. - source: salt://home_assistant/files/configuration.yaml
  63. - template: jinja
  64. - user: home_assistant
  65. - mode: 600
  66. - require:
  67. - file: home_assistant_dir
  68. {%- if server.known_device is defined %}
  69. home_assistant_know_devices:
  70. file.managed:
  71. - name: /etc/home_assistant/known_devices.yaml
  72. - source: salt://home_assistant/files/known_devices.yaml
  73. - template: jinja
  74. - user: home_assistant
  75. - mode: 600
  76. - require:
  77. - file: home_assistant_dir
  78. {%- endif %}
  79. {%- endif %}
  80. home_assistant_service_script:
  81. file.managed:
  82. - name: /etc/systemd/system/home-assistant.service
  83. - source: salt://home_assistant/files/home-assistant.service
  84. - template: jinja
  85. - user: root
  86. - mode: 644
  87. - watch_in:
  88. - module: home_assistant_restart_systemd
  89. home_assistant_service:
  90. service.running:
  91. - name: home-assistant
  92. - enable: true
  93. - watch:
  94. - module: home_assistant_restart_systemd
  95. - file: home_assistant_service_script
  96. home_assistant_restart_systemd:
  97. module.wait:
  98. - name: service.systemctl_reload
  99. {%- endif %}