Influencing the order of the sections with to_yaml() ?

18 views
Skip to first unread message

Robert Kulagowski

unread,
Mar 11, 2024, 5:02:10 PM3/11/24
to cloudtools-dev
troposphere 4.7.0 on python 3.10.12

I've generated a fairly long YAML formatted file, but when I look at the YAML it's hard to follow. While it may be syntactically correct, it isn't very human readable. For example, although I'm adding Description first in my template, the resulting to_yaml() puts it after "Conditions". 

And the resource names are being sorted alphabetically; in my loop I'm using f-strings with the words "One", "Two", "Three", "Four", "Five". Even though the resources are being added in the above order, in the template they're appearing as $fooFive, $fooFour, $fooOne, $fooThree and $fooTwo

How can I get the resulting template outputted in the order that the elements were added instead of in alphabetical order?

Thanks!

Mark Peek

unread,
Mar 11, 2024, 5:35:21 PM3/11/24
to Robert Kulagowski, cloudtools-dev
Robert,
First off, please try using to_yaml(sort_keys=False) to see if that gets closer to what you are wanting. There might be a way to add OrderedDict to the mix but I'd still want the current behavior since people might rely on it. Please post your findings and a small example with expected output into a github issue.

Mark

--
You received this message because you are subscribed to the Google Groups "cloudtools-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloudtools-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloudtools-dev/6b06ca40-8b68-4f8f-b49b-14af939295cfn%40googlegroups.com.

Robert Kulagowski

unread,
Mar 11, 2024, 5:58:46 PM3/11/24
to cloudtools-dev
On Monday, March 11, 2024 at 4:35:21 PM UTC-5 mark wrote:
Robert,
First off, please try using to_yaml(sort_keys=False) to see if that gets closer to what you are wanting.

It's exactly what I needed. Thanks!
 
Reply all
Reply to author
Forward
0 new messages