Merge "Fix package dependencies"
diff --git a/README.rst b/README.rst
index 3e155d6..e741ac8 100644
--- a/README.rst
+++ b/README.rst
@@ -17,6 +17,11 @@
tftpd_hpa:
server:
enabled: true
+ username: 'tftp'
+ path: '/var/lib/tftproot'
+ options:
+ - secure
+ - map-file: '/var/lib/tftproot/map-file'
More information
diff --git a/tests/pillar/server_single.sls b/tests/pillar/server_single.sls
index e6d8346..7c73b29 100644
--- a/tests/pillar/server_single.sls
+++ b/tests/pillar/server_single.sls
@@ -1,4 +1,10 @@
tftpd_hpa:
server:
enabled: true
-
+ bind:
+ address: '0.0.0.0'
+ port: 69
+ username: 'root'
+ options:
+ - secure
+ - map-file: '/var/lib/tftproot/map-file'
diff --git a/tftpd_hpa/files/tftpd-hpa.conf b/tftpd_hpa/files/tftpd-hpa.conf
new file mode 100644
index 0000000..089f15e
--- /dev/null
+++ b/tftpd_hpa/files/tftpd-hpa.conf
@@ -0,0 +1,15 @@
+{%- from "tftpd_hpa/map.jinja" import server with context %}
+{%- set opts = [] %}
+{%- for data in server.get('options', []) %}
+{%- if data is mapping %}
+{%- for opt, val in data.iteritems() %}
+{%- do opts.append('--' + opt + ' ' + val) %}
+{%- endfor %}
+{%- else %}
+{%- do opts.append("--" + data) %}
+{%- endif %}
+{%- endfor -%}
+TFTP_USERNAME="{{ server.username }}"
+TFTP_DIRECTORY="{{ server.path }}"
+TFTP_ADDRESS="{{ server.bind.address }}:{{ server.bind.port }}"
+TFTP_OPTIONS="{{ ' '.join(opts) }}"
diff --git a/tftpd_hpa/map.jinja b/tftpd_hpa/map.jinja
index 64fee22..15596b1 100644
--- a/tftpd_hpa/map.jinja
+++ b/tftpd_hpa/map.jinja
@@ -1,21 +1,25 @@
+{% set server = salt['grains.filter_by']({
+ 'Common': {
+ 'service': 'tftpd-hpa',
+ 'path': '/var/lib/tftpboot',
+ 'username': 'tftp',
+ 'bind': {
+ 'address': '',
+ 'port': 69
+ },
+ 'options': ['--secure']
+ },
+ 'Debian': {
+ 'pkgs': ['tftpd-hpa', 'syslinux'],
+ 'config_file': '/etc/default/tftpd-hpa'
+ },
+ 'RedHat': {
+ 'pkgs': ['tftp-server', 'syslinux']
+ }
+}, base='Common', merge=salt['grains.filter_by']({
+ 'Ubuntu': {
+ 'path': '/srv/tftp'
+ },
+}, grain='os')) %}
-{%- load_yaml as raw_server %}
-Debian:
- pkgs:
- - tftpd-hpa
- - syslinux
- {%- if salt['grains.get']('os') == 'Ubuntu' %}
- path: /var/lib/tftpboot
- {%- else %}
- path: /srv/tftp
- {%- endif %}
- service: tftpd-hpa
-RedHat:
- pkgs:
- - tftp-server
- - syslinux
- root: /var/lib/tftpboot/
- service: tftpd-hpa
-{%- endload %}
-
-{%- set server = salt['grains.filter_by'](raw_server, merge=salt['pillar.get']('tftpd_hpa:server')) %}
+{% do server.update(pillar.tftpd_hpa.get('server', {})) %}
diff --git a/tftpd_hpa/server.sls b/tftpd_hpa/server.sls
index eb716d3..a022d18 100644
--- a/tftpd_hpa/server.sls
+++ b/tftpd_hpa/server.sls
@@ -5,10 +5,24 @@
pkg.installed:
- pkgs: {{ server.pkgs }}
+{{ server.config_file }}:
+ file.managed:
+ - name: {{ server.config_file }}
+ source: salt://tftpd_hpa/files/tftpd-hpa.conf
+ template: jinja
+
tftpd_hpa_service:
service.running:
- name: {{ server.service }}
- enable: true
- running: true
+ - watch:
+ - file: {{ server.config_file }}
-{%- endif %}
\ No newline at end of file
+{{ server.path }}:
+ file.directory:
+ - makedirs: True
+ - name: {{ server.path }}
+ - user: {{ server.username }}
+
+{%- endif %}