ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
13.5k stars 3.34k forks source link

AWX task fail with AnsibleUnsafeBytes for yaml collapsed string #15161

Closed jon-nfc closed 2 weeks ago

jon-nfc commented 2 weeks ago

Please confirm the following

Bug Summary

A yaml collapsed string with jinja fails with error AnsibleUnsafeBytes.__format__. unsupported format string passed to AnsibleUnsafeBytes.__format__ when it should not have for a string. this task does not fail when run via CLI.

AWX version

23.9.0

Select the relevant components

Installation method

kubernetes

Modifications

no

Ansible version

2.16.1

Operating system

k3s 1.29

Web browser

No response

Steps to reproduce

use the foollowing task in play:

- name: Download K3s Binary
  ansible.builtin.uri:
    url: |-
      https://github.com/k3s-io/k3s/releases/download/
        {{- node_k3s.desired_version | urlencode -}}
      /k3s
      {%- if cpu_arch.key == 'aarch64' -%}
      -arm64
      {%- endif %}
    method: GET
    return_content: false
    status_code:
      - 200
      - 304
    dest: "/tmp/k3s.{{ cpu_arch.key }}"
    mode: "744"
  changed_when: not ansible_check_mode
  check_mode: false
  delay: 10
  retries: 3
  register: k3s_download_files
  delegate_to: localhost
  failed_when: >
    (lookup('ansible.builtin.file', '/tmp/k3s.' + cpu_arch.key) | hash('sha256') | string) != node_k3s.desired_hash
      and
    (
      k3s_download_files.status | int != 200
        or
      k3s_download_files.status | int != 304
    )
  run_once: true
  when: ansible_os_family == 'Debian'
  loop: "{{ nfc_kubernetes_install_architectures | dict2items }}"
  loop_control:
    loop_var: cpu_arch
  vars:
    ansible_connection: local

where:

cpu_arch:
  key: aarch64

Expected results

A yaml collapsed string |- or >- by never return error AnsibleUnsafeBytes.__format__. unsupported. when the type is clearly a yaml string

Actual results

error:


msg: >-
  Unexpected templating type error occurred on
  (https://github.com/k3s-io/k3s/releases/download/
    {{- node_k3s.desired_version | urlencode -}}
  /k3s

  {%- if cpu_arch.key == 'aarch64' -%}

  -arm64

  {%- endif %}): unsupported format string passed to
  AnsibleUnsafeBytes.__format__. unsupported format string passed to
  AnsibleUnsafeBytes.__format__

Additional information

No response

jon-nfc commented 2 weeks ago

closing as issue was corrected by updating to ansible-core 2.16.6 from 2.16.1