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

Ansible setup_controller become_password_file issue

Open shaerpour opened this issue 8 months ago • 4 comments

Bug report

I was testing if I can use become_password_file option in ansible setup_controller but it returns error.

Steps to reproduce the problem

user-data:

#cloud-config
password: password
chpasswd:
  expire: False
system_info:
  default_user:
    name: ubuntu
    sudo: ALL=(ALL) ALL
ansible:
  install_method: distro
  run_user: ubuntu
  package_name: ansible-core
  setup_controller:
    repositories:
      - source: "https://github.com/shaerpour/test.git"
        path: "/tmp/test/"
    run_ansible:
      - playbook_name: "play.yml"
        playbook_dir: "/tmp/test/"
        become_password_file: "pass.txt"

playbook:

- name: test
  hosts: localhost
  connection: local
  gather_facts: false
  become: true
  tasks:
    - name: test
      copy:
        content: "test cloud-init"
        dest: "/root/test.txt"

Environment details

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

cloud-init logs

ubuntu@ubuntu:~$ cloud-init status --long
status: error
extended_status: error - done
boot_status_code: enabled-by-generator
last_update: Thu, 01 Jan 1970 00:00:29 +0000
detail: DataSourceNoCloud [seed=dmi,/dev/sr0][dsmode=local]
errors:
        - ('ansible', ProcessExecutionError("Unexpected error while running command.\nCommand: ['su', '-', 'ubuntu', '-c', 'cd /tmp/test/ && env PATH=$PATH ansible-playbook play.yml --become-password-file=pass.txt']\nExit code: 250\nReason: -\nStdout: to see the full traceback, use -vvv\nStderr: ERROR! Unexpected Exception, this is probably a bug: module 'posixpath' has no attribute 'is_executable'"))
recoverable_errors:
DEPRECATED:
        - Deprecated cloud-config provided: system_info:  Deprecated in version 24.2. System and/or distro specific settings. This is not intended to be overridden by user-data or vendor-data.
        - Deprecated cloud-config provided: system_info:  Deprecated in version 24.2. System and/or distro specific settings. This is not intended to be overridden by user-data or vendor-data.
        - Deprecated cloud-config provided: system_info:  Deprecated in version 24.2. System and/or distro specific settings. This is not intended to be overridden by user-data or vendor-data.
        - Deprecated cloud-config provided: system_info:  Deprecated in version 24.2. System and/or distro specific settings. This is not intended to be overridden by user-data or vendor-data.
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

I'm currently working on this issue to see if I can find a solution.

shaerpour avatar Apr 14 '25 09:04 shaerpour

Ubuntu Jammy does not have an updated ansible-core version that fixed this bug. You're either using outdate ansible-core or aren't installing the base modules collections.

kolonelkrazy avatar Apr 14 '25 19:04 kolonelkrazy

Dear @kolonelkrazy Thanks for your response. So you are saying we can't use setup_controller with install_method: distro in jammy or older versions. Because they install official repo's ansible version that it's outdated.

shaerpour avatar Apr 15 '25 09:04 shaerpour

From what I can remember that seems to be the case; this is all I have from my notes around that time:

There was an issue for this: https://github.com/ansible/ansible/issues/76530

It got cherry picked a few times from devel to backports: https://github.com/ansible/ansible/pull/76558

and it didn't land in a official release until here: https://github.com/ansible/ansible/commit/6fa408a99af16ea99e034750cfa35fcad5a70905

@shaerpour Figure out what ansible-core version you're using inside the image. If it's earlier than 2.12 then this is likely the problem

kolonelkrazy avatar Apr 15 '25 13:04 kolonelkrazy

We should probably think about what action we should do for that. install_method: pip is probably OK because it installs last version by default but distro will cause issue.

shaerpour avatar Apr 15 '25 15:04 shaerpour