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

to_nice_yaml producing "..." (3 dots) on role vars but not template vars #17095

Closed
joaocc opened this issue Aug 15, 2016 · 5 comments
Closed
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@joaocc
Copy link

joaocc commented Aug 15, 2016

ISSUE TYPE
  • Bug Report
COMPONENT NAME

template and to_nice_yaml filter

ANSIBLE VERSION

ansible 2.1.1.0

CONFIGURATION

ANSIBLE_JINJA2_EXTENSIONS=jinja2.ext.do,jinja2.ext.i18n,jinja2.ext.loopcontrols,jinja2.ext.with_
ANSIBLE_PRIVATE_ROLE_VARS=true

OS / ENVIRONMENT

N/A

SUMMARY

While attempting to use 'template' to generate a YAML file, I noticed that 'to_nice_yaml' produces trailing "..." (3 dots) after outputting some variables, but not other.
This happens with role variables that are used directly inside the template, but not with objects that are obtained through loop variables.

STEPS TO REPRODUCE

templates/_debug.yml.j2


---
{% set ii=(item[1].j2_item) %}
{% set aa=(item[1].j2_args) %}
REPRO__TO_NICE_YAML:
    fromitem:
{{ aa.rolevars.id |to_nice_yaml |indent(8,true) }}
    fromrole:
        test1:
{{ myrole__id      |to_nice_yaml |indent(10, true) }}
        test2:
{{ myrole__id      |to_nice_yaml(false,false) |indent(10, true) }}
        test3:
{{ myrole__id      |to_nice_yaml(explicit_start=False, explicit_end=False) |indent(10, true) }}

output file

loop_config (outer)

  vars:
    j2_args:
      role_vars:
        id:      "{{ myrole__id }}"
  loop_control:
    loop_var: j2_item
  with_flattened:
    - "{{ files_1 }}"
    - "{{ files_2 }}"

loop_config (inner)

- template:
    src:  "{{ item[0].path }}"
    dest: "{{ j2_item.dst }}"
  with_nested:
    - "{{ _X_j2_find_files.files }}"
    - [ {
            j2_item: "{{ j2_item }}",
            j2_args: "{{ j2_args }}"
        }
      ]
EXPECTED RESULTS

desired output file


---
REPRO__TO_NICE_YAML:
    fromitem:
        0base
    fromrole:
        test1:
          0base
        test2:
          0base
        test3:
          0base
ACTUAL RESULTS

---
REPRO__TO_NICE_YAML:
    fromitem:
        0base
        ...
    fromrole:
        test1:
          0base
          ...
        test2:
          0base
          ...
        test3:
          0base
          ...
@ansibot ansibot added triage affects_2.1 This issue/PR affects Ansible v2.1 labels Sep 7, 2016
@ansibot ansibot added module This issue/PR relates to a module. plugin and removed module This issue/PR relates to a module. plugin labels Dec 13, 2016
@bcoca bcoca removed the triage label Dec 16, 2016
@sivel
Copy link
Member

sivel commented Apr 7, 2017

I've done a little bit of research here, and the first thing that I notice, is that you seem to be passing just a plain string through to_nice_yaml, such as the string 0base. I'm not exactly sure why you would need to do that.

Based on that, and what I can tell of the yaml emitter, it looks to see if you are writing a plain string, and that plain string is the root document, and if so, it appends a line reading ...

The ... line indicates "end of document" in yaml (http://yaml.org/spec/1.1/#id857577)

If I use any other data type, other than a scalar, pyyaml does not insert the ...

Based on this, I'd have to assume that you shouldn't be piping your scalar values through to_nice_yaml as there doesn't seem to be any need for it.

@sivel sivel added the needs_info This issue requires further information. Please answer any outstanding questions. label Apr 7, 2017
@joaocc
Copy link
Author

joaocc commented Apr 7, 2017

Hi @sivel.
At this distance in time, I think the reason for using to_nice_yaml with a string had to do with wanting to ensure a properly formatted string (with escaping if needed), and also for flexibility in allowing the variables to contain other non-string values if needed.
While I understand your comment of "..." at end of document, shouldn't the explicit_end=False flag prevent the ... from being shown?
Thanks

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Apr 7, 2017
@sivel
Copy link
Member

sivel commented Apr 7, 2017

From what I could tell looking through the pyyaml code, explicit_end has no bearing on this situation.

I think at this point, this bug has less to do with ansible and more with the behavior of pyyaml.

@Phrozyn
Copy link

Phrozyn commented Apr 7, 2017

I had this problem yesterday, and responded to this thread, but ended up removing my comment.
It's not an ansible issue to be clear.

For me it was a journey - through jinja2 and templates.
I got the ... on a new line, but that appeared to be due to using a list of items with only one item in it (I had started with more than 1 item but ansible wants to put [] around them, and I didn't need those.
So I consolidated the list into a comma separated value with single quotes and that fixed the ... and [] issue.

@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibot ansibot added the module This issue/PR relates to a module. label Aug 14, 2017
@sivel
Copy link
Member

sivel commented Feb 20, 2018

Going to close this out. There isn't anything for ansible to do here. This is expected based on the behavior of pyyaml.

@sivel sivel closed this as completed Feb 20, 2018
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

6 participants