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

apt_repository errors out with multiline strings with trailing newline #82393

Open
1 task done
jonasPoehler opened this issue Dec 11, 2023 · 3 comments
Open
1 task done
Labels
affects_2.16 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation

Comments

@jonasPoehler
Copy link

jonasPoehler commented Dec 11, 2023

Summary

I tried to switch from Ansible 2.15.7 to 2.16.1 and discovered, that apt_repository fails on me when I try to run a task as described in the steps to reproduce.

I did some quick debugging and saw, that in module_utils/basic.py:376 the buffere contains some json including the input with its newline. The newline then causes json.loads to fail.

My simple (and probably correct) fix was to replace > with >- to strip the trailing newline. However, I did not find any mention of this behaviour change in the porting guide (since this did work in 2.15.7) and without some debugging I could have never known the true reason for this error, so the error message could be improved (verbose logging did not help).

Issue Type

Bug Report

Component Name

apt_repository

Ansible Version

$ ansible --version
ansible [core 2.16.1]
  config file = /home/poehler/dev/ansible/ansible.cfg
  configured module search path = ['/home/poehler/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/poehler/dev/ansible/venv/lib/python3.11/site-packages/ansible
  ansible collection location = /home/poehler/dev/ansible/collections:/home/poehler/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/poehler/dev/ansible/venv/bin/ansible
  python version = 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] (/home/poehler/dev/ansible/venv/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CALLBACKS_ENABLED(/home/poehler/dev/ansible/ansible.cfg) = ['foconis_prometheus_push_callback']
COLLECTIONS_PATHS(/home/poehler/dev/ansible/ansible.cfg) = ['/home/poehler/dev/ansible/collections', '/home/poehler/.ansible/collections', '/usr/share/ansible/collections']
CONFIG_FILE() = /home/poehler/dev/ansible/ansible.cfg
DEFAULT_CALLBACK_PLUGIN_PATH(/home/poehler/dev/ansible/ansible.cfg) = ['/usr/share/ansible/plugins/callback', '/home/poehler/dev/ansible/plugins/callback']
DEFAULT_FORKS(/home/poehler/dev/ansible/ansible.cfg) = 10
DEFAULT_GATHERING(/home/poehler/dev/ansible/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/poehler/dev/ansible/ansible.cfg) = ['/home/poehler/dev/ansible/hosts']
DEFAULT_ROLES_PATH(/home/poehler/dev/ansible/ansible.cfg) = ['/home/poehler/dev/ansible/roles', '/home/poehler/.ansible/roles', '/usr/share/ansible/roles', '/etc/ansible/roles']
DEFAULT_STDOUT_CALLBACK(/home/poehler/dev/ansible/ansible.cfg) = yaml
DEFAULT_VARS_PLUGIN_PATH(/home/poehler/dev/ansible/ansible.cfg) = ['/usr/share/ansible/plugins/vars', '/home/poehler/dev/ansible/plugins/vars']
DISPLAY_SKIPPED_HOSTS(/home/poehler/dev/ansible/ansible.cfg) = False
PAGER(env: PAGER) = less

CALLBACK:
========

foconis_prometheus_push_callback:
________________________________
gateway_url(/home/poehler/dev/ansible/ansible.cfg) = https://some.url

default:
_______
display_skipped_hosts(/home/poehler/dev/ansible/ansible.cfg) = False

CONNECTION:
==========

ssh:
___
pipelining(/home/poehler/dev/ansible/ansible.cfg) = True

OS / Environment

Ubuntu 23.10 running on WSL

Steps to Reproduce

- name: "Remove old docker repository configuration"
  ansible.builtin.apt_repository:
    repo: >
      deb [arch=amd64]
      https://download.docker.com/linux/{{ ansible_distribution | lower if ansible_distribution == 'Debian' or
      ansible_distribution == 'Ubuntu' else omit }} {{ ansible_lsb.codename }} stable
    filename: docker
    state: absent

Expected Results

Either this just works (as in 2.15) or the error I get is more helpful for me to actually understand, what I'm doing wrong.

Actual Results

TASK [docker : Remove old docker repository configuration] *********************************************************************************************************************************************************************************************************************************************************
task path: /home/poehler/dev/ansible/roles/docker/tasks/install.yml:30
fatal: [localhost]: FAILED! => changed=false 
  msg: 'Error: Module unable to decode valid JSON on stdin.  Unable to figure out what parameters were passed'

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. affects_2.16 module This issue/PR relates to a module. labels Dec 11, 2023
@ansibot
Copy link
Contributor

ansibot commented Dec 11, 2023

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the component bot command.

@bcoca bcoca added P3 Priority 3 - Approved, No Time Limitation needs_verified This issue needs to be verified/reproduced by maintainer and removed needs_triage Needs a first human triage before being processed. labels Dec 12, 2023
@lkthomas
Copy link

lower if ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' else omit <- could you try to use "when:" instead so you reduce the complexity on the "repo:" section?

Example:
when: ansible_os_family == "Debian"

@jonasPoehler
Copy link
Author

could you try to use "when:" instead so you reduce the complexity on the "repo:" section?

That's kinda the point of me creating this issue. I have a couple of such templates with apt_repository and the problem is not the complexity of the template, but rather the behaviour with newlines in these templates changing from 2.15 to 2.16. Obviously I can rewrite this template to be a bit simpler, but this isn't relevant to the issue since you could remove the templating in its entirety and the problem would still be here, as long as I have to introduce linebreaks.

- name: "Remove old docker repository configuration"
  ansible.builtin.apt_repository:
    repo: >
      deb [arch=amd64]
      https://download.docker.com/linux/ubuntu mantic stable
    filename: docker
    state: absent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.16 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation
Projects
None yet
Development

No branches or pull requests

4 participants