Skip to content

Commit

Permalink
feat: disabling keys sorting in to_nice_yaml (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: Przemyslaw Kalitowski <[email protected]>
Co-authored-by: Ivan Aragonés Muniesa <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent 49aec89 commit 7b896e4
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
minor_changes:
- filetree_create is able to export variables without key sorting
...
4 changes: 2 additions & 2 deletions roles/filetree_create/templates/current_credential_types.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ controller_credential_types:
kind: "{{ credential_type.kind }}"
inputs:
{{ template_overrides_resources.credential_type[credential_type.name].inputs
| default(credential_type.inputs) | to_nice_yaml(indent=2) | indent(width=6, first=True) }}
| default(credential_type.inputs) | to_nice_yaml(indent=2,sort_keys=False) | indent(width=6, first=True) }}
{% if template_overrides_resources.credential_type[credential_type.name].injectors is defined
or (credential_type.injectors and credential_type.injectors != '---') %}
injectors:
{# https://docs.ansible.com/ansible/latest/user_guide/playbooks_advanced_syntax.html#unsafe-or-raw-strings #}
{{ template_overrides_resources.credential_type[credential_type.name].injectors
| default(credential_type.injectors)
| to_nice_yaml(indent=2) | indent(width=6, first=True) | replace("'{{", "!unsafe \'{{") }}
| to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=True) | replace("'{{", "!unsafe \'{{") }}
{%- endif %}
{% endfor %}
...
4 changes: 2 additions & 2 deletions roles/filetree_create/templates/current_credentials.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ controller_credentials:
or (current_credentials_asset_value.inputs is defined and current_credentials_asset_value.inputs is not match('{}')) %}
inputs:
{% if show_encrypted is defined and show_encrypted %}
{{ current_credentials_asset_value.inputs | to_nice_yaml(indent=2) | indent(width=6, first=True) }}
{{ current_credentials_asset_value.inputs | to_nice_yaml(indent=2 | sort_keys=False) | indent(width=6, first=True) }}
{% else %}
{{ template_overrides_resources.credential[current_credentials_asset_value.name].inputs
| default(current_credentials_asset_value.inputs)
| to_nice_yaml(indent=2) | indent(width=6, first=True) | replace("$encrypted$", "\'\'") }}
| to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=True) | replace("$encrypted$", "\'\'") }}
{% endif %}
{% endif %}
{% if last_credential | default(true) | bool %}
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/templates/current_groups.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ controller_groups:
{{ template_overrides_resources.group[group.name].variables
| default(template_overrides_global.group.variables)
| default(group.variables)
| from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
{%- endif %}
hosts:
{{ query(controller_api_plugin, group.related.hosts,
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/templates/current_hosts.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ controller_hosts:
{{ template_overrides_resources.host[host.name].variables
| default(template_overrides_global.host.variables)
| default(host.variables)
| from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
{%- endif %}
{% endfor %}
...
4 changes: 2 additions & 2 deletions roles/filetree_create/templates/current_inventories.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ controller_inventories:
{{ template_overrides_resources.inventory[current_inventories_asset_value.name].source_vars
| default(template_overrides_global.inventory.source_vars)
| default(current_inventories_asset_value.source_vars)
| from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
{% endif %}
{% if template_overrides_resources.inventory[current_inventories_asset_value.name].update_cache_timeout is defined
or template_overrides_global_global.inventory.update_cache_timeout is defined
Expand Down Expand Up @@ -61,7 +61,7 @@ controller_inventories:
{{ template_overrides_resources.inventory[current_inventories_asset_value.name].variables
| default(template_overrides_global.inventory.variables)
| default(current_inventories_asset_value.variables)
| from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
{%- endif %}
{% if last_inventory | default(true) | bool %}
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ controller_inventory_sources:
{{ template_overrides_resources.inventory_source[inventory_source.name].source_vars
| default(template_overrides_global.inventory_source.source_vars)
| default(inventory_source.source_vars)
| from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
{%- endif %}
inventory: "{{ inventory_source.summary_fields.inventory.name }}"
update_on_launch: "{{ template_overrides_resources.inventory_source[inventory_source.name].update_on_launch
Expand Down
4 changes: 2 additions & 2 deletions roles/filetree_create/templates/current_job_templates.j2
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ controller_templates:
{{ template_overrides_resources.job_template[current_job_templates_asset_value.name].extra_vars
| default(template_overrides_global.job_template.extra_vars)
| default(current_job_templates_asset_value.extra_vars)
| from_yaml | to_nice_yaml(indent=2)
| from_yaml | to_nice_yaml(indent=2, sort_keys=False)
| indent(width=6, first=False)
| regex_replace('(^[^:]*): (.*){{', '\1: !unsafe \2{{', multiline=True)
}}
Expand Down Expand Up @@ -194,7 +194,7 @@ controller_templates:
| default(template_overrides_global.job_template.survey_spec)
| default(query(controller_api_plugin, current_job_templates_asset_value.related.survey_spec,
host=controller_hostname, oauth_token=controller_oauthtoken, verify_ssl=controller_validate_certs)[0])
| from_yaml | to_nice_yaml(indent=2,width=500) | regex_replace("\n\n[ ]*", "\\\\n")
| from_yaml | to_nice_yaml(indent=2,width=500,sort_keys=False) | regex_replace("\n\n[ ]*", "\\\\n")
| indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") | replace("^$", "") | replace("$encrypted$", "")
-%}
{% if template_overrides_resources.job_template[current_job_templates_asset_value.name].survey_spec is defined
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/templates/current_schedules.j2
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ controller_schedules:
{{ template_overrides_resources.schedule[current_schedules_asset_value.name].extra_data
| default(template_overrides_global.schedule.extra_data)
| default(current_schedules_asset_value.extra_data)
| from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") | replace("$encrypted$", "") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") | replace("$encrypted$", "") }}
{%- endif -%}
{% if query_credentials | length > 0 %}
credentials:
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/templates/current_settings.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ controller_settings:
{% for key,value in changed_settings[0].items() %}
{% if value is mapping or value | type_debug == "list" %}
{{ key | indent(width=6, first=True) }}:
{{ value | to_nice_yaml(indent=2) | indent(width=8, first=True) }}
{{ value | to_nice_yaml(indent=2, sort_keys=false) | indent(width=8, first=True) }}
{%- else %}
{{ key | indent(width=6, first=True) }}: "{{ value | replace('True', 'true') | replace('False', 'false') | replace('None', 'null') }}"
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ controller_workflows:
all_parents_must_converge: "{{ node.all_parents_must_converge }}"
{% if node.extra_data is defined and node.extra_data | length > 0 %}
extra_data:
{{ node.extra_data | to_nice_yaml | indent(10) | replace("'{{", "!unsafe \'{{") | replace("$encrypted$", "") }}
{{ node.extra_data | to_nice_yaml(sort_keys=false) | indent(10) | replace("'{{", "!unsafe \'{{") | replace("$encrypted$", "") }}
{%- endif %}
{% if node.success_nodes is defined and node.success_nodes | length > 0 %}
success_nodes:
Expand Down Expand Up @@ -65,7 +65,7 @@ controller_workflows:
{{ template_overrides_resources.workflow_job_template[current_workflow_job_templates_asset_value.name].extra_vars
| default(template_overrides_global.workflow_template.extra_vars)
| default(current_workflow_job_templates_asset_value.extra_vars)
| from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){{', '\1: !unsafe \2{{', multiline=True) }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){{', '\1: !unsafe \2{{', multiline=True) }}
{%- endif %}
{% if query_labels | length > 0 %}
labels:
Expand Down Expand Up @@ -104,7 +104,7 @@ controller_workflows:
| default(template_overrides_global.workflow_job_template.survey_spec)
| default(query(controller_api_plugin, current_workflow_job_templates_asset_value.related.survey_spec,
host=controller_hostname, oauth_token=controller_oauthtoken, verify_ssl=controller_validate_certs)[0])
| from_yaml | to_nice_yaml(indent=2,width=500) | regex_replace("\n\n[ ]*", "\\\\n")
| from_yaml | to_nice_yaml(indent=2,width=500, sort_keys=False) | regex_replace("\n\n[ ]*", "\\\\n")
| indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") | replace("^$", "") | replace("$encrypted$", "")
-%}
{% if template_overrides_resources.workflow_job_template[current_workflow_job_templates_asset_value.name].survey_spec is defined
Expand Down

0 comments on commit 7b896e4

Please sign in to comment.