Merge "Fixed shebang kernel limitation with virtualenv during test run (https://github.com/pypa/virtualenv/issues/596)"
diff --git a/README.rst b/README.rst
index ee0c53d..ed21934 100644
--- a/README.rst
+++ b/README.rst
@@ -350,13 +350,20 @@
         file:
           /tmp/test.txt:
             source: http://example.com/test.txt
-            user: root
-            group: root
-            mode: 700
-            dir_mode: 700
-            encoding: utf-8
-            hash: <<md5 hash>>
-            makedirs: true
+            user: root #optional
+            group: root #optional
+            mode: 700 #optional
+            dir_mode: 700 #optional
+            encoding: utf-8 #optional
+            hash: <<hash>> or <<URI to hash>> #optional
+            makedirs: true #optional
+
+    linux:
+      system:
+        file:
+          test.txt:
+            name: /tmp/test.txt
+            source: http://example.com/test.txt
 
 Ensure presence of file by specifying it's contents:
 
@@ -369,13 +376,19 @@
             contents: |
               line1
               line2
-            user: root
-            group: root
-            mode: 700
-            dir_mode: 700
-            encoding: utf-8
-            hash: <<md5 hash>>
-            makedirs: true
+
+    linux:
+      system:
+        file:
+          /tmp/test.txt:
+            contents_pillar: linux:network:hostname
+
+    linux:
+      system:
+        file:
+          /tmp/test.txt:
+            contents_grains: motd
+
 Kernel
 ~~~~~~
 
diff --git a/linux/system/file.sls b/linux/system/file.sls
index c13d7da..ba24860 100644
--- a/linux/system/file.sls
+++ b/linux/system/file.sls
@@ -3,16 +3,26 @@
 
 {%- for file_name, file in system.file.iteritems() %}
 
-{{ file_name }}:
+linux_file_{{ file_name }}:
   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 %}
+    - source_hash: {{ file.hash }}
+    {%- else %}
+    - skip_verify: True
     {%- endif %}
-    {%- if file.contents is defined %}
-    - contents: {{ file.contents }}
-    {%- endif %}
-    {%- if file.contents_pillar is defined %}
+    {%- elif file.contents is defined %}
+    - contents: {{ file.contents|yaml }}
+    {%- elif file.contents_pillar is defined %}
     - contents_pillar: {{ file.contents_pillar }}
+    {%- elif file.contents_grains is defined %}
+    - contents_grains: {{ file.contents_grains }}
     {%- endif %}
     - makedirs: {{ file.get('makedirs', 'True') }}
     - user: {{ file.get('user', 'root') }}
@@ -26,11 +36,6 @@
     {%- if file.encoding is defined %}
     - encoding: {{ file.encoding }}
     {%- endif %}
-    {%- if file.hash is defined %}
-    - source_hash: {{ file.hash }}
-    {%- else %}
-    - skip_verify: True
-    {%- endif %}
 
 {%- endfor %}
 
diff --git a/tests/pillar/system_file.sls b/tests/pillar/system_file.sls
new file mode 100644
index 0000000..8de464b
--- /dev/null
+++ b/tests/pillar/system_file.sls
@@ -0,0 +1,21 @@
+linux:
+  system:
+    enabled: true
+    file:
+      /tmp/sample.txt:
+        source: http://techslides.com/demos/samples/sample.txt
+        source_hash: 5452459724e85b4e12277d5f8aab8fc9
+      sample2.txt:
+        name: /tmp/sample2.txt
+        source: http://techslides.com/demos/samples/sample.txt
+      test2:
+        name: /tmp/test2.txt
+        contents: |
+          line1
+          line2
+        user: root
+        group: root
+        mode: 700
+        dir_mode: 700
+        encoding: utf-8
+        makedirs: true
\ No newline at end of file