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

Fix hostfilter and add missing unsafe regex #28

Merged
merged 11 commits into from
Nov 15, 2024
4 changes: 4 additions & 0 deletions changelogs/fragments/filetree_create_hostfilter_issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- filetree_create exported properly smart inventories host filter (double quotes issue)
...
4 changes: 4 additions & 0 deletions changelogs/fragments/filetree_create_unsafe_regex_issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- filetree_create properly escape every variable with unsafe
...
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ controller_credential_types:
{# 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, sort_keys=False) | indent(width=6, first=True) | replace("'{{", "!unsafe \'{{") }}
| to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=True) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)}}
{%- endif %}
{% endfor %}
...
4 changes: 2 additions & 2 deletions roles/filetree_create/templates/controller_groups.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ 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, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)}}
{%- endif %}
hosts:
{{ query(controller_api_plugin, group.related.hosts,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs,
return_all=true, max_objects=query_controller_api_max_objects
) | selectattr("name", "defined") | map(attribute="name") | to_nice_yaml(indent=2) | indent(width=6, first=True)
) | selectattr("name", "defined") | map(attribute="name") | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=True)
}}
{%- endfor -%}
...
2 changes: 1 addition & 1 deletion roles/filetree_create/templates/controller_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, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)}}
{%- endif %}
{% endfor %}
...
8 changes: 4 additions & 4 deletions roles/filetree_create/templates/controller_inventories.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ controller_inventories:
{% if template_overrides_resources.inventory[current_inventories_asset_value.name].host_filter is defined
or template_overrides_global_global.inventory.host_filter is defined
or current_inventories_asset_value.host_filter is defined %}
host_filter: "{{ template_overrides_resources.inventory[current_inventories_asset_value.name].host_filter
host_filter: {{ template_overrides_resources.inventory[current_inventories_asset_value.name].host_filter
| default(template_overrides_global.inventory.host_filter)
| default(current_inventories_asset_value.host_filter) }}"
| default(current_inventories_asset_value.host_filter) | replace("'",'"') }}
{% endif %}
{% if current_inventories_asset_value.kind %}
kind: "{{ current_inventories_asset_value.kind }}"
Expand All @@ -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, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)}}
{% 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, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") | replace("'{%", "!unsafe \'{%") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)}}
{%- 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, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)}}
{%- endif %}
inventory: "{{ inventory_source.summary_fields.inventory.name }}"
update_on_launch: "{{ template_overrides_resources.inventory_source[inventory_source.name].update_on_launch
Expand Down
6 changes: 3 additions & 3 deletions roles/filetree_create/templates/controller_job_templates.j2
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ controller_templates:
| default(current_job_templates_asset_value.extra_vars)
| from_yaml | to_nice_yaml(indent=2, sort_keys=False)
| indent(width=6, first=False)
| regex_replace('(^[^:]*): (.*){{', '\\g<1>: !unsafe \\g<2>{{', multiline=True)
| regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)
}}
{%- endif %}
job_tags: "{{ template_overrides_resources.job_template[current_job_templates_asset_value.name].job_tags
Expand Down Expand Up @@ -195,8 +195,8 @@ controller_templates:
| default(query(controller_api_plugin, current_job_templates_asset_value.related.survey_spec,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs)[0])
| 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$", "\'\'")
| replace("'", '"') | regex_replace('default: ([^"].*)', 'default: "\\g<1>"')
| indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)
| replace("^$", "") | replace("$encrypted$", "\'\'"))
-%}
{% if template_overrides_resources.job_template[current_job_templates_asset_value.name].survey_spec is defined
or template_overrides_global.job_template.survey_spec is defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ controller_notifications:
{% endfor %}
{% if current_notification_templates_asset_value.messages is defined and current_notification_templates_asset_value.messages %}
messages:
{{ current_notification_templates_asset_value.messages | to_nice_yaml(indent=2) | indent(width=6, first=True) | replace("'{{", "!unsafe \'{{") | replace("body: '", "body: !unsafe \'") }}
{{ current_notification_templates_asset_value.messages | to_nice_yaml(indent=2, sort_keys=false) | indent(width=6, first=True) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True) | replace("body: '", "body: !unsafe \'") }}
{% endif %}
{% if last_notification_template | default(true) | bool %}
...
Expand Down
2 changes: 1 addition & 1 deletion roles/filetree_create/templates/controller_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, sort_keys=False) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") | replace("$encrypted$", "\'\'") }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True) | replace("$encrypted$", "\'\'") }}
{%- endif -%}
{% if query_credentials | length > 0 %}
credentials:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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(sort_keys=false) | indent(10) | replace("'{{", "!unsafe \'{{") | replace("$encrypted$", "\'\'") }}
{{ node.extra_data | to_nice_yaml(sort_keys=false) | indent(10) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)| replace("$encrypted$", "\'\'") }}
{%- endif %}
{% if node.success_nodes is defined and node.success_nodes | length > 0 %}
success_nodes:
Expand Down Expand Up @@ -73,7 +73,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, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){{', '\\g<1>: !unsafe \\g<2>{{', multiline=True) }}
| from_yaml | to_nice_yaml(indent=2, sort_keys=False) | indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True) }}
{%- endif %}
{% if query_labels | length > 0 %}
labels:
Expand Down Expand Up @@ -113,8 +113,8 @@ controller_workflows:
| default(query(controller_api_plugin, current_workflow_job_templates_asset_value.related.survey_spec,
host=aap_hostname, oauth_token=aap_oauthtoken, verify_ssl=controller_validate_certs)[0])
| 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$", "\'\'")
| replace("'", '"') | regex_replace('default: ([^"].*)', 'default: "\\g<1>"')
| indent(width=6, first=False) | regex_replace('(^[^:]*): (.*){([{%])', '\\g<1>: !unsafe \\g<2>{\\g<3>', multiline=True)
| replace("^$", "") | replace("$encrypted$", "\'\'")
-%}
{% if template_overrides_resources.workflow_job_template[current_workflow_job_templates_asset_value.name].survey_spec is defined
or template_overrides_global.workflow_job_template.survey_spec is defined
Expand Down