jmoney-main ~ master # cat /srv/salt/test.sls
mod_udm:
file.append:
- name: C:\salt\udm.conf
- source: salt://udm.txt
jmoney-main ~ master # cat /srv/salt/udm.txt
License_Product "EVENT MONITOR SERVER"
License_Customer "AXA"
License_OS_Type "NT"
License_Type "LEASE"
License_Expiration_Date 2018.10.31 YYYY.MM.DD
License_File_Monitoring yes
License_Key xxxxxxxxxxxxxxxxxxxxxxxxxxxx
An existing file at the destination path on the minion was already created at the implication of the usage file.append
.
jmoney-main ~ master # salt jmoney-windows-12 cmd.run 'type c:\\salt\\udm.conf'
jmoney-windows-12:
test
The source file (salt://udm.txt
) contains only 7 lines, but the state application inserts 14 lines, where 7 are blank.
jmoney-main ~ master # salt jmoney-windows-12 state.apply test
jmoney-windows-12:
----------
ID: mod_udm
Function: file.append
Name: C:\salt\udm.conf
Result: True
Comment: Appended 7 lines
Started: 21:08:53.972000
Duration: 218.0 ms
Changes:
----------
diff:
---
+++
@@ -1 +1,15 @@
test
+
+License_Product "EVENT MONITOR SERVER"
+
+License_Customer "AXA"
+
+License_OS_Type "NT"
+
+License_Type "LEASE"
+
+License_Expiration_Date 2018.10.31 YYYY.MM.DD
+
+License_File_Monitoring yes
+
+License_Key xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Summary for jmoney-windows-12
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
This can also be seen by inspecting the destination file (c:\salt\udm.conf
) manually after the state application.
jmoney-main ~ master # salt jmoney-windows-12 cmd.run 'type c:\\salt\\udm.conf'
jmoney-windows-12:
test
License_Product "EVENT MONITOR SERVER"
License_Customer "AXA"
License_OS_Type "NT"
License_Type "LEASE"
License_Expiration_Date 2018.10.31 YYYY.MM.DD
License_File_Monitoring yes
License_Key xxxxxxxxxxxxxxxxxxxxxxxxxxxx
jmoney-windows-12:
Salt Version:
Salt: 2015.8.9
Dependency Versions:
Jinja2: 2.7.3
M2Crypto: Not Installed
Mako: Not Installed
PyYAML: 3.11
PyZMQ: 14.7.0
Python: 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)]
RAET: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.2
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.4.2
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
libgit2: Not Installed
libnacl: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
python-gnupg: 0.3.7
smmap: Not Installed
timelib: Not Installed
System Versions:
dist:
machine: AMD64
release: 2012ServerR2
system: 2012ServerR2 6.3.9600 Multiprocessor Free
The easiest workaround is to use salt to manage the whole file.
jmoney-main ~ master # cat /srv/salt/test.sls
mod_udm:
file.managed:
- name: C:\salt\udm.conf
- source: salt://udm.txt
file.managed
removes the spurious blank lines.
jmoney-main ~ master # salt jmoney-windows-12 state.apply test
jmoney-windows-12:
----------
ID: mod_udm
Function: file.managed
Name: C:\salt\udm.conf
Result: True
Comment: File C:\salt\udm.conf updated
Started: 21:22:36.081000
Duration: 172.0 ms
Changes:
----------
diff:
---
+++
@@ -1,15 +1,7 @@
-test
-
License_Product "EVENT MONITOR SERVER"
-
License_Customer "AXA"
-
License_OS_Type "NT"
-
License_Type "LEASE"
-
License_Expiration_Date 2018.10.31 YYYY.MM.DD
-
License_File_Monitoring yes
-
License_Key xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Summary for jmoney-windows-12
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
jmoney-main ~ master # salt jmoney-windows-12 cmd.run 'type c:\\salt\\udm.conf'
jmoney-windows-12:
License_Product "EVENT MONITOR SERVER"
License_Customer "AXA"
License_OS_Type "NT"
License_Type "LEASE"
License_Expiration_Date 2018.10.31 YYYY.MM.DD
License_File_Monitoring yes
License_Key xxxxxxxxxxxxxxxxxxxxxxxxxxxx
However, when the file is stated with file.managed
, the line endings are incorrect for windows and all of the lines are concatenated, when viewed with notepad, for example.
License_Product "EVENT MONITOR SERVER"License_Customer"AXA"License_OS_Type"NT"License_Type"LEASE"License_Expiration_Date2018.10.31 YYYY.MM.DDLicense_File_Monitoring yesLicense_Key xxxxxxxxxxxxxxxxxxxxxxxxxxxx
The
file.managed
problem has to do with unix vs dos line endings. The file is being copied down, it's not interpreted line by line with os specific line endings added. To fix this, open the file with vim and type:set fileformat=dos
. Then it will come down with the correct formatting.