config_template does not respect yaml multiline as overrides

Bug #1819974 reported by Itxaka Serrano
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack-Ansible
Fix Released
Undecided
Georgina Shippey

Bug Description

If you pass a multiline value as config overrides with yaml output it will split the multiline and export something completely wrong:

Given the following overrides:

test_overrides:
  test: |
    This is multiline on yaml
    The newlines should be respected
    but they are not
    is it a bug?

With the following template:

---
cat1: cool
cat2: notsocool

And the following task:

- name: "test multiline merge"
  config_template:
    src: "test.j2"
    dest: "test.yaml"
    config_overrides: "{{ test_overrides }}"
    config_type: yaml
  delegate_to: localhost

Expected:

cat1: cool
cat2: notsocool
test: |
  This is multiline on yaml
  The newlines should be respected
  but they are not
  is it a bug?

But got:
cat1: cool
cat2: notsocool
test:
  - This is multiline on yaml
  - The newlines should be respected
  - but they are not
  - is it a bug?

This is probably due to the line https://github.com/openstack/ansible-config_template/blob/master/action/config_template.py#L562 in which we check if the value contains a "\n" and split based of that, but that will always result in broken multilines from yaml.
The parsing of the values up to that point seems good to me.

Not sure how to solve it, maybe we should have a flag to *not* split the values? In the end this is changing a multiline into a list which could lead to unwanted consequences

Changed in openstack-ansible:
assignee: nobody → Kevin Carter (kevin-carter)
Changed in openstack-ansible:
assignee: Kevin Carter (kevin-carter) → Georgina Shippey (gshippey)
Revision history for this message
Itxaka Serrano (itxaka) wrote :

If you do the other way, having the multiline in the template instead of the overrides, it still doesn't output the correct multiline.

Given the following overrides:

test_overrides:
  cat1: cool
  cat2: notsocool

With the following template:

---
test: |
  This is multiline on yaml
  The newlines should be respected
  but they are not
  is it a bug?

And the following task:

- name: "test multiline merge"
  config_template:
    src: "test.j2"
    dest: "test.yaml"
    config_overrides: "{{ test_overrides }}"
    config_type: yaml
  delegate_to: localhost

Expected:

cat1: cool
cat2: notsocool
test: |
  This is multiline on yaml
  The newlines should be respected
  but they are not
  is it a bug?

But got:

Expected:

cat1: cool
cat2: notsocool
test: |-
  This is multiline on yaml
  The newlines should be respected
  but they are not
  is it a bug?

The subtle difference is that we are adding the "-" to the multiline for some reason which we should not do as it may change what is expected from the output.

Sure this is a minor thing as it only stripes the last line, but something to take into account. We dont want to change the output for no good reason :D

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ansible-config_template (master)

Fix proposed to branch: master
Review: https://review.opendev.org/655496

Changed in openstack-ansible:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ansible-config_template (master)

Reviewed: https://review.opendev.org/655496
Committed: https://git.openstack.org/cgit/openstack/ansible-config_template/commit/?id=1769158a0e4ce66a8030ed66220268560c08ae0b
Submitter: Zuul
Branch: master

commit 1769158a0e4ce66a8030ed66220268560c08ae0b
Author: Georgina <email address hidden>
Date: Wed Apr 24 16:27:21 2019 +0000

    config_template does not respect yaml multiline as overrides

    Added a flag called yml_multilines which when used will not split on
    lines that have a newline UNLESS they have a comma.

    Change-Id: I90364403e215a67b320dfc7e67a85d47c774e634
    Partial-Bug: #1819974

Changed in openstack-ansible:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.