Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: bad label format for complex variable #49

Open
drzraf opened this issue Nov 2, 2020 · 1 comment
Open

Error: bad label format for complex variable #49

drzraf opened this issue Nov 2, 2020 · 1 comment

Comments

@drzraf
Copy link

drzraf commented Nov 2, 2020

Trying to output a complex (dict) variable triggers a
Error: bad label format

<table border="0" cellborder="0">
  <tr><td><b>
  <font face="Times New Roman, Bold" point-size="16">foo</font>
  </b></td></tr>
<hr/><tr><td><font face="Times New Roman, Bold" point-size="14">ansible_python_interpreter<br/>ansible_user<br/>os_servers = {'foo': {'bar': 'DE'}}<br/></font></td></tr></table>
@drzraf
Copy link
Author

drzraf commented Nov 2, 2020

I suggest the addition of the following filter:

import re
from ansible.parsing.yaml.objects import AnsibleSequence
def to_string(value, indent = 1):
    o = ''
    if isinstance(value, AnsibleSequence) or isinstance(value, list):
        return "- " + "<br/>- ".join(value) + "<br/>"
    if not isinstance(value, dict):
        return value
    for k, v in value.items():
        o += " " * indent  + f"{k}: {to_string(v, indent + 2)}<br/>"
    return re.sub(r'["{}\(\)|]*', '', o)

# env.filters['to_string'] = to_string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant