Repository navigation
Closed as not planned
Description
Description of Issue/Question
I am using import_yaml to load a YAML file that has some keys with empty values (Ex.: key:), then use file.serialize to write it to a YAML file again. But all keys that previously had no values, now have a None in place, which is a valid string, but not a valid YAML empty value.
This is causing problems because the program that expects an empty or decimal value is getting a string instead.
Setup
{% import_yaml "defaults.yaml" as defaults %}
{{ sls }}~config:
file.serialize:
- name: /etc/config.yaml
- show_changes: true
- formatter: yaml
- backup: minion
- dataset: {{ defaults }}
Steps to Reproduce Issue
Can be verified using state.show_sls.
Versions Report
Salt Version:
Salt: 2017.7.1
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.4.2
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: Not Installed
Jinja2: 2.8
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.2.0
RAET: Not Installed
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: Ubuntu 16.04 xenial
locale: UTF-8
machine: x86_64
release: 4.4.0-96-generic
system: Linux
version: Ubuntu 16.04 xenial
Reacted by Ricardo Saffi Marques, Ahmed AbouZaid, Andrew Dampf, Harveen Singh Chadha, MitchDrage and Sachin Patel
Metadata
Metadata
Assignees
Labels
ConfirmedSalt engineer has confirmed bug/feature - often including a MCVECorerelates to code central or existential to Saltbugbroken, incorrect, or confusing behaviorseverity-low4th level, cosemtic problems, work around existsstale
Activity
gtmanfred commentedon Sep 22, 2017
PyYaml converts empty values to
Nonewhen they are put in the yaml dictionary, and I am not sure how you would differentiate between having None or empty when dumping back to a file.I am going to mark this as a bug, but I would highly recommend using file.managed if you and values to remain empty instead of having None specified.
Thanks,
Daniel
gtmanfred commentedon Sep 25, 2017
Ok, so it is an easy solution to solve.
I am just not sure if it should be "solved" for everyone by default or not. It might make more sense to set it to
'null'.The other problem is if we change this behavior, Then any files dumped from this module won't be readable by salts yaml loader.
@saltstack/team-core does anyone have any suggestions here?
Thanks,
Daniel
norpol commentedon Oct 3, 2017
I have a similar problem.
import_yaml ...wrongly escapes the content. Sonull, becomesNone,\nbecomes\\n,truebecomesTrue.to
{'a': None, 'b': 'null', 'c': 'null\\nnull\\nnull'}This is appears when I do a
file.serializeorfile.managedwith eitherdatasetorcontents.I've managed to ?workaround? this problem by passing the
import_yamldict through|yamlin my jinja.Example:
stale commentedon Feb 7, 2019
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
norpol commentedon Feb 17, 2019
I think this is still an issue.
3 remaining items
garethgreenaway commentedon Feb 18, 2019
@rallytime done.
baby-gnu commentedon Jun 7, 2019
I have the same issue when using
~liketerminalmage commentedon Jun 7, 2019
A tilde is a null value in YAML. Are you trying to get a literal tilde? If so you'll need to quote it.
baby-gnu commentedon Jun 7, 2019
Hello @terminalmage, I want a
Nonebut today that's not what I got.Looks like I have an issue with my macros, I
import_yamland call a macro with the value:is nonetestis none.Sorry for the noise, I should have missed something.
stale commentedon Jan 8, 2020
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
stale commentedon Jan 8, 2020
Thank you for updating this issue. It is no longer marked as stale.
dwoz commentedon Oct 15, 2026
Thanks for the original report. This issue has been open for more than three years without recent activity and carries a severity label below
severity-high. As part of a backlog cleanup, we're closing older low- and medium-severity issues so triage can focus on reports against currently supported releases.Closing isn't a judgement that the problem wasn't real — only that the codebase has moved through several releases since this was filed, and much of the surrounding code has changed.
If you — or anyone else — can still reproduce this on the 3008.x LTS release, please leave a comment with a reproduction and a maintainer will reopen. The original reporter can also reopen directly.