Skip to content

New format filter with value(s) as input rather than format string (to make is usable with map and a list of values) #11412

@VannTen

Description

@VannTen

Summary

I would like to be able to format a list of dictionnary (or tuple, or simple items) using the same format string.

This can't be done with the jinja filter format because the string is the input / first parameters, so using with map is only useful for passing differents format string rather than differents values.

I don't have a strong opinion on the syntax (of the format string), but I think something like str.format would be simple enough ?

I'm willing to make the PR myself if the feature is considered worthwhile.

Issue Type

Feature Idea

Component Name

filters

Additional Information

# Ansible variables
list_of_docker_images:
- repo: docker.io
  image: alpine
  tag: v3.4.5
  digest: sha256:xxxxxxxxx
- repo: k8s.io
  image: kube-proxy
  tag: v1.34.0
  digest: sha256:yyyyyyyyy
list_of_full_image_names: "{{ list_of_docker_images | map('some_format_filter', '{repo}/{image}:{tag}@{digest}')
# => ['docker.io/alpine:v3.4.5@sha256:xxx', 'k8s.io/kube-proxy:v1.34.0@sha256:yyyyyyy']

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureThis issue/PR relates to a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions