Rendering out regular expressions (special characters)
Description of Issue/Question
Hello,
I'm trying to render out a grok pattern file with some regular expressions. But salt / jinja keeps adding additional \ characters. The expected output of the patterns file is as follows:
GREEDYMULTILINE (.|\n)*
CONNECTION (dis)?connect
Actual output is as follows:
GREEDYMULTILINE (.|\\n)*
CONNECTION (dis)?connect
Thanks in advance.
Setup
defaults.yml file:
config:
patterns:
listing:
GREEDYMULTILINE: '(.|\\n)*'
CONNECTION '(dis)?connect'
The state file patterns.sls:
{% from "defaults.yaml" import rawmap with context %}
{%- set defaults = salt['grains.filter_by'](rawmap) %}
{%- set Patterns = defaults.config.patterns %}
config_custom_patterns:
file.managed:
- name: '/etc/custom/patterns'
- source: 'salt://files/patterns'
- template: 'jinja'
- context:
patterns: {{ Patterns.listing }}
- user: 'root'
- group: 'root'
- mode: '0644'
- makedirs: True
- dir_mode: '0755'
- backup: 'minion'
Patterns template patterns:
{%- for Key, Value in patterns.iteritems() -%}
{{ Key }} {{ Value }}
{% endfor %}
Steps to Reproduce Issue
salt 'test' state.apply patterns
Versions Report
Master:
Salt Version:
Salt: 2017.7.0
Dependency Versions:
cffi: 1.6.0
cherrypy: Not Installed
dateutil: Not Installed
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: 1.3.8
Jinja2: 2.7.2
libgit2: 0.24.6
libnacl: 1.4.3
M2Crypto: 0.21.1
Mako: 0.8.1
msgpack-pure: Not Installed
msgpack-python: 0.4.8
mysql-python: Not Installed
pycparser: 2.14
pycrypto: 2.6.1
pycryptodome: 3.4.3
pygit2: 0.24.2
Python: 2.7.5 (default, Nov 6 2016, 00:28:07)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.3.0
RAET: 0.6.5
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: centos 7.3.1611 Core
locale: UTF-8
machine: x86_64
release: 3.10.0-514.26.2.el7.x86_64
system: Linux
version: CentOS Linux 7.3.1611 Core
Minion:
Salt Version:
Salt: 2017.7.2
Dependency Versions:
cffi: 1.6.0
cherrypy: Not Installed
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: 1.3.8
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: 1.4.3
M2Crypto: Not Installed
Mako: 0.8.1
msgpack-pure: Not Installed
msgpack-python: 0.4.8
mysql-python: Not Installed
pycparser: 2.14
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.5 (default, Aug 4 2017, 00:39:18)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.3.0
RAET: 0.6.5
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4
System Versions:
dist: centos 7.4.1708 Core
locale: UTF-8
machine: x86_64
release: 3.10.0-327.el7.x86_64
system: Linux
version: CentOS Linux 7.4.1708 Core
if you change it to double quotes does it help. Like this: GREEDYMULTILINE: "(.|\n)*"
@Ch3LL I'll give that a try.
@Ch3LL, unfortunately your suggestion didn't work.
It looks like the setup actually contains the double-backslash, in single quotes, which is then faithfully written to the file. No extra characters. Or are my eyes failing me?
@lorengordon if I don't use double quotes, I get Jinja errors.
You get an error without double backslashes, even when the string is inside the single quotes? Can you post the traceback/error?
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.