[BUG] file.keyvalue doesn't preserve indentation
Open
Nobody has claimed this yet.
bug
Core
severity-medium
State-Module
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
file.keyvalue doesn't preserve indentation of key:value pairs in configuration file.
Setup
- Create the configuration file to be modified on the minion:
# cat << EOF > /tmp/test.txt
<VirtualHost *:80>
ServerName YOUR_SERVER_FQDN
ServerSignature Off
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
</VirtualHost>
EOF
- Create the following state:
file_keyvalue_test:
file.keyvalue:
- name: /tmp/test.txt
- key: ServerName
- value: host.example.com
- separator: ' '
- key_ignore_case: False
- append_if_not_found: False
Steps to Reproduce the behavior
3. Apply the state:
# salt host.example.com state.apply
host.example.com:
----------
----------
ID: file_keyvalue_test
Function: file.keyvalue
Name: /tmp/test.txt
Result: True
Comment: Changed 1 lines
Started: 22:46:00.444384
Duration: 6.222 ms
Changes:
----------
diff:
- ServerName YOUR_SERVER_FQDN
+ ServerName host.example.com
Summary for host.example.com
-------------
Succeeded: 1 (changed=1)
Failed: 0
- View the file on minion:
# cat /tmp/test.txt
<VirtualHost *:80>
ServerName host.example.com
ServerSignature Off
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
</VirtualHost>
Expected behavior
file.keyvalue should preserve indentation of key:value pairs:
# cat /tmp/test.txt
<VirtualHost *:80>
ServerName host.example.com
ServerSignature Off
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
</VirtualHost>
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)# salt --versions-report
Salt Version:
Salt: 3001.1
Dependency Versions:
cffi: 1.11.5
cherrypy: unknown
dateutil: 2.6.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: 0.35.2
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.6.2
mysql-python: Not Installed
pycparser: 2.14
pycrypto: Not Installed
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.8 (default, Apr 16 2020, 01:36:27)
python-gnupg: Not Installed
PyYAML: 3.12
PyZMQ: 19.0.0
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2
System Versions:
dist: centos 8 Core
locale: UTF-8
machine: x86_64
release: 4.18.0-193.19.1.el8_2.x86_64
system: Linux
version: CentOS Linux 8 Core
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the file.keyvalue state entry point and reproduce the issue using the /tmp/test.txt configuration and state shown in the report. Trace how the matching ServerName line is replaced, then add coverage for its two-space indentation. Done means applying the state changes the value while preserving the original indentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100