Skip to content

helm_template stdout contains non-yaml output #1017

@serpro69

Description

@serpro69
SUMMARY

Trying to render nginx template in one task, and then apply them in another.
But I noticed that the stdout from helm_template contains other output from helm when the charts are downloaded, which then of course fails when I try to apply directly from stdout.

Don't know if this is a bug, just wondering, am I doing something wrong here, or how is this supposed to work for such use-case?

ISSUE TYPE
  • Bug Report
COMPONENT NAME

helm_template

ANSIBLE VERSION
ansible [core 2.18.7]
  config file = /Users/sergio/Projects/***/ansible/ansible.cfg
  configured module search path = ['/Users/sergio/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /nix/store/a31k23mld4df676p9j1n87akzd8rb29g-python3.12-ansible-core-2.18.7/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/sergio/Projects/***/ansible/galaxy/collections
  executable location = /nix/store/a31k23mld4df676p9j1n87akzd8rb29g-python3.12-ansible-core-2.18.7/bin/ansible
  python version = 3.12.11 (main, Jun  3 2025, 15:41:47) [Clang 19.1.7 ] (/nix/store/v21kg4vm7yy0wflh0avkibz0shk86jn8-python3-3.12.11/bin/python3.12)
  jinja version = 3.1.6
  libyaml = True
COLLECTION VERSION
# /Users/sergio/Projects/***/ansible/galaxy/collections/ansible_collections
Collection      Version
--------------- -------
kubernetes.core 6.2.0

# /nix/store/m61na0mcz8fj8g299dqx6r4l80p181pc-python3.12-ansible-11.8.0/lib/python3.12/site-packages/ansible_collections
Collection      Version
--------------- -------
kubernetes.core 5.3.0
CONFIGURATION
ANSIBLE_FORCE_COLOR(/Users/sergio/Projects/***/ansible/ansible.cfg) = True
COLLECTIONS_PATHS(/Users/sergio/Projects/***/ansible/ansible.cfg) = ['/Users/sergio/Projects/***/ansible/galaxy/collections']
CONFIG_FILE() = /Users/sergio/Projects/***/ansible/ansible.cfg
DEFAULT_ROLES_PATH(/Users/sergio/Projects/***/ansible/ansible.cfg) = ['/Users/sergio/Projects/***/ansible/galaxy/roles']
DEFAULT_STDOUT_CALLBACK(/Users/sergio/Projects/***/ansible/ansible.cfg) = yaml
EDITOR(env: EDITOR) = vim
HOST_KEY_CHECKING(/Users/sergio/Projects/***/ansible/ansible.cfg) = False
PAGER(env: PAGER) = /usr/bin/less
OS / ENVIRONMENT
STEPS TO REPRODUCE
    - name: Render nginx manifests from helm chart
      kubernetes.core.helm_template:
        chart_ref: ../kubernetes/nginx
        include_crds: true
        release_name: ingress-nginx
        release_namespace: ingress-nginx
        dependency_update: true
        values_files:
          - ../kubernetes/nginx/values.yaml
      register: nginx_manifests

    - name: Apply nginx manifests
      kubernetes.core.k8s:
        resource_definition: "{{ nginx_manifests.stdout }}"
        apply: true
EXPECTED RESULTS

You should be able to get just the rendered templates w/o writing them to files, not the entire helm output.

ACTUAL RESULTS

The stdout starts with standard helm output, and then contains the rendered templates:

Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "ingress-nginx" chart repository
...Successfully got an update from the "jetstack" chart repository
Update Complete. ⎈Happy Helming!⎈
Saving 1 charts
Downloading ingress-nginx from repo https://kubernetes.github.io/ingress-nginx
Deleting outdated charts
---
# Source: nginx/charts/ingress-nginx/templates/controller-poddisruptionbudget.yaml
# PDB is not supported for DaemonSets.
# https://github.com/kubernetes/kubernetes/issues/108124
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  ...

So on first run, if charts need to be downloaded, apply task will fail with: ''str'' object has no attribute ''setdefault''' since it's not a valid yml.

TASK [Apply nginx manifests] ******************************************************************************************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions.CoreException: Failed to load resource definition: 'str' object has no attribute 'setdefault'
fatal: [localhost]: FAILED! => changed=false
  msg: 'Failed to load resource definition: ''str'' object has no attribute ''setdefault'''

I suspect I might be doing something wrong here, so would appreciate some tips on how to solve this.
Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions