Add support file.serialize in linux:system:file
Ensure presence of file to be serialized through one of the serializer modules
(see: https://docs.saltstack.com/en/latest/ref/serializers/all/index.html):
diff --git a/README.rst b/README.rst
index 2765990..45139c4 100644
--- a/README.rst
+++ b/README.rst
@@ -389,6 +389,20 @@
/tmp/test.txt:
contents_grains: motd
+Ensure presence of file to be serialized through one of the serializer modules
+(see: https://docs.saltstack.com/en/latest/ref/serializers/all/index.html):
+
+.. code-block:: yaml
+
+ linux:
+ system:
+ file:
+ /tmp/test.json:
+ serialize: json
+ contents:
+ foo: 1
+ bar: 'bar'
+
Kernel
~~~~~~
diff --git a/linux/system/file.sls b/linux/system/file.sls
index 0de42fe..ffc1d76 100644
--- a/linux/system/file.sls
+++ b/linux/system/file.sls
@@ -4,12 +4,16 @@
{%- for file_name, file in system.file.items() %}
linux_file_{{ file_name }}:
+{%- if file.serialize is defined %}
+ file.serialize:
+ - formatter: {{ file.serialize }}
+ {%- if file.contents is defined %}
+ - dataset: {{ file.contents|yaml }}
+ {%- elif file.contents_pillar is defined %}
+ - dataset_pillar: {{ file.contents_pillar }}
+ {%- endif %}
+{%- else %}
file.managed:
- {%- if file.name is defined %}
- - name: {{ file.name }}
- {%- else %}
- - name: {{ file_name }}
- {%- endif %}
{%- if file.source is defined %}
- source: {{ file.source }}
{%- if file.hash is defined %}
@@ -24,6 +28,12 @@
{%- elif file.contents_grains is defined %}
- contents_grains: {{ file.contents_grains }}
{%- endif %}
+{%- endif %}
+ {%- if file.name is defined %}
+ - name: {{ file.name }}
+ {%- else %}
+ - name: {{ file_name }}
+ {%- endif %}
- makedirs: {{ file.get('makedirs', 'True') }}
- user: {{ file.get('user', 'root') }}
- group: {{ file.get('group', 'root') }}