cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

ansible: pip install_method not working if run_user is set

Open shaerpour opened this issue 8 months ago • 0 comments

Bug report

pip install_method with run_user option is broke.

In #6021 MR, after removing single quotes, pip install_method is not working as expected because shell tries to use them as arguments and not passing them to python itself.

su - ubuntu -c env PATH=$PATH /usr/bin/python3 -c import site; print(site.getuserbase())

It makes command like above that.

Steps to reproduce the problem

#cloud-config
password: password
chpasswd:
  expire: False
ansible:
  install_method: pip
  run_user: ubuntu
  package_name: ansible-core
  pull:
    url: https://github.com/shaerpour/test.git
    playbook_name: play.yml

Environment details

  • Cloud-init version: 25.1.1
  • Operating System Distribution: Ubuntu jammy
  • Cloud provider, platform or installer type: QEMU

cloud-init logs

status: error extended_status: error - done boot_status_code: enabled-by-generator last_update: Thu, 01 Jan 1970 00:00:09 +0000 detail: DataSourceNoCloud [seed=dmi,/dev/sr0][dsmode=local] errors: - ('ansible', ProcessExecutionError("Unexpected error while running command.\nCommand: ['su', '-', 'ubuntu', '-c', 'env PATH=$PATH /usr/bin/python3 -c import site; print(site.getuserbase())']\nExit code: 2\nReason: -\nStdout: \nStderr: -bash: -c: line 1: syntax error near unexpected token site.getuserbase'\n -bash: -c: line 1: env PATH=$PATH /usr/bin/python3 -c import site; print(site.getuserbase())'")) recoverable_errors: WARNING: - Running module ansible (<module 'cloudinit.config.cc_ansible' from '/usr/local/lib/python3.10/dist-packages/cloud_init-25.1.1-py3.10.egg/cloudinit/config/cc_ansible.py'>) failed

shaerpour avatar Apr 16 '25 13:04 shaerpour