diff --git a/changelogs/fragments/fix_init_commented.yml b/changelogs/fragments/fix_init_commented.yml new file mode 100644 index 00000000000..e177b58d02d --- /dev/null +++ b/changelogs/fragments/fix_init_commented.yml @@ -0,0 +1,3 @@ +bugfixes: + - "`ansible-config init -f vars` will now use shorthand format" + - ansible-configi init should now skip internal reserved config entries diff --git a/lib/ansible/cli/config.py b/lib/ansible/cli/config.py index 81243ae46e1..13c46f15641 100755 --- a/lib/ansible/cli/config.py +++ b/lib/ansible/cli/config.py @@ -36,7 +36,7 @@ display = Display() def yaml_dump(data, default_flow_style=True): - return yaml.dump(data, Dumper=AnsibleDumper, default_flow_style=default_flow_style) + return yaml.dump(data, Dumper=AnsibleDumper, default_flow_style=default_flow_style, default_style="''") def get_constants(): @@ -299,9 +299,13 @@ class ConfigCLI(CLI): # TODO: might need quoting and value coercion depending on type if subkey == 'env': + if entry.startswith('_ANSIBLE_'): + continue data.append('%s%s=%s' % (prefix, entry, default)) elif subkey == 'vars': - data.append(prefix + to_text(yaml_dump({entry: default}, default_flow_style=False), errors='surrogate_or_strict')) + if entry.startswith('_ansible_'): + continue + data.append(prefix + '%s: %s' % (entry, to_text(yaml_dump(default), errors='surrogate_or_strict'))) data.append('') return data