ansible.builtin.apt autoremove doesn't remove anything while similar ansible.builtin.command does
Author: 4wk-Created Aug 8, 2024Updated Sep 22, 2026
Labelsmodulebughas_prverifiedaffects_2.17
Summary
In some occasion (it worked fine before), ansible.builtin.apt with autoremove: true seems to not work properly (= no package to remove - but there is!).
I've tried with and without purge: true / --purge -> same issue.
Issue Type
Bug Report
Component Name
apt
Ansible Version
$ ansible --version
ansible [core 2.17.2]
config file = /home/foobar/ansible/ansible.cfg
configured module search path = ['/home/foobar/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/foobar/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.11.2 (main, May 2 2024, 11:59:08) [GCC 12.2.0] (/opt/pipx/venvs/ansible/bin/python)
jinja version = 3.1.4
libyaml = TrueConfiguration
# 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/foobar/ansible/ansible.cfg) = ['timer', 'profile_roles']
CONFIG_FILE() = /home/foobar/ansible/ansible.cfg
DEFAULT_BECOME_METHOD(/home/foobar/ansible/ansible.cfg) = sudoOS / Environment
Debian 12.6 in wsl
Steps to Reproduce
- name: ONE apt autoremove builtin module
ansible.builtin.apt:
autoremove: true
purge: true
# Doesnt work in check_mode..
# https://github.com/ansible/ansible/issues/83626
#diff: yes
tags:
- apt-autoremove
- name: TWO apt autoremove with command module
ansible.builtin.command:
cmd: sudo apt autoremove --purge --dry-run
register: cmd_output
tags:
- apt-autoremove
- name: show command output
debug:
msg: "{{ cmd_output}}"
tags:
- apt-autoremovePlaybook run: ansible-playbook -i inventories/test/ playbook.yml --limit "myhost" --tags apt-autoremove --diff
Expected Results
I expect task ONE to actually remove the packages that need to be autoremoved (libgpgme11* libtokyocabinet9* linux-image-5.10.0-26-amd64*).
Actual Results
TASK [apt : apt autoremove builtin module] ***************************************************
task path: /home/foobar/ansible/roles/apt/tasks/main.yml:126
Thursday 08 August 2024 10:45:54 +0200 (0:00:00.011) 0:00:00.011 *******
<176.149.236.226> ESTABLISH SSH CONNECTION FOR USER: ansible
<176.149.236.226> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=442 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="ansible"' -o ConnectTimeout=10 -o 'ControlPath="/home/foobar/.ansible/cp/707b007166"' 176.149.236.226 '/bin/sh -c '"'"'echo ~ansible && sleep 0'"'"''
<176.149.236.226> (0, b'/home/ansible\n', b'OpenSSH_9.2p1 Debian-2+deb12u3, OpenSSL 3.0.13 30 Jan 2024\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for 176.149.236.226\r\ndebug2: resolve_canonicalize: hostname 176.149.236.226 is address\r\ndebug3: expanded UserKnownHostsFile \'~/.ssh/known_hosts\' -> \'/home/foobar/.ssh/known_hosts\'\r\ndebug3: expanded UserKnownHostsFile \'~/.ssh/known_hosts2\' -> \'/home/foobar/.ssh/known_hosts2\'\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket "/home/foobar/.ansible/cp/707b007166" does not exist\r\ndebug3: ssh_connect_direct: entering\r\ndebug1: Connecting to 176.149.236.226 [176.149.236.226] port 442.\r\ndebug3: set_sock_tos: set socket 3 IP_TOS 0x10\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug1: fd 3 clearing O_NONBLOCK\r\ndebug1: Connection established.\r\ndebug3: timeout: 9984 ms remain after connect\r\ndebug1: identity file /home/foobar/.ssh/id_rsa type -1\r\ndebug1: identity file /home/foobar/.ssh/id_rsa-cert type -1\r\ndebug1: identity file /home/foobar/.ssh/id_ecdsa type -1\r\ndebug1: identity file /home/foobar/.ssh/id_ecdsa-cert type -1\r\ndebug1: identity file /home/foobar/.ssh/id_ecdsa_sk type -1\r\ndebug1: identity file /home/foobar/.ssh/id_ecdsa_sk-cert type -1\r\ndebug1: identity file /home/foobar/.ssh/id_ed25519 type -1\r\ndebug1: identity file /home/foobar/.ssh/id_ed25519-cert type -1\r\ndebug1: identity file /home/foobar/.ssh/id_ed25519_sk type -1\r\ndebug1: identity file /home/foobar/.ssh/id_ed25519_sk-cert type -1\r\ndebug1: identity file /home/foobar/.ssh/id_xmss type -1\r\ndebug1: identity file /home/foobar/.ssh/id_xmss-cert type -1\r\ndebug1: identity file /home/foobar/.ssh/id_dsa type -1\r\ndebug1: identity file /home/foobar/.ssh/id_dsa-cert type -1\r\ndebug1: Local version string SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u3\r\ndebug1: Remote protocol version 2.0, remote software version OpenSSH_8.4p1 Debian-5+deb11u3\r\ndebug1: compat_banner: match: OpenSSH_8.4p1 Debian-5+deb11u3 pat OpenSSH* compat 0x04000000\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug1: Authenticating to 176.149.236.226:442 as \'ansible\'\r\ndebug3: put_host_port: [176.149.236.226]:442\r\ndebug3: record_hostkey: found key type ECDSA in file /home/foobar/.ssh/known_hosts:9\r\ndebug3: record_hostkey: found key type ED25519 in file /home/foobar/.ssh/known_hosts:12\r\ndebug3: load_hostkeys_file: loaded 2 keys from [176.149.236.226]:442\r\ndebug1: load_hostkeys: fopen /home/foobar/.ssh/known_hosts2: No such file or directory\r\ndebug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory\r\ndebug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory\r\ndebug3: order_hostkeyalgs: have matching best-preference key type [email protected], using HostkeyAlgorithms verbatim\r\ndebug3: send packet: type 20\r\ndebug1: SSH2_MSG_KEXINIT sent\r\ndebug3: receive packet: type 20\r\ndebug1: SSH2_MSG_KEXINIT received\r\ndebug2: local client KEXINIT proposal\r\ndebug2: KEX algorithms: [email protected],curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c,[email protected]\r\ndebug2: host key algorithms: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa\r\ndebug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]\r\ndebug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]\r\ndebug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2: compression ctos: [email protected],zlib,none\r\ndebug2: compression stoc: [email protected],zlib,none\r\ndebug2: languages ctos: \r\ndebug2: languages stoc: \r\ndebug2: first_kex_follows 0 \r\ndebug2: reserved 0 \r\ndebug2: peer server KEXINIT proposal\r\ndebug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,[email protected]\r\ndebug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519\r\ndebug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]\r\ndebug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]\r\ndebug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1\r\ndebug2: compression ctos: none,[email protected]\r\ndebug2: compression stoc: none,[email protected]\r\ndebug2: languages ctos: \r\ndebug2: languages stoc: \r\ndebug2: first_kex_follows 0 \r\ndebug2: reserved 0 \r\ndebug3: kex_choose_conf: will use strict KEX ordering\r\ndebug1: kex: algorithm: curve25519-sha256\r\ndebug1: kex: host key algorithm: ssh-ed25519\r\ndebug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: [email protected]\r\ndebug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: [email protected]\r\ndebug3: send packet: type 30\r\ndebug1: expecting SSH2_MSG_KEX_ECDH_REPLY\r\ndebug3: receive packet: type 31\r\ndebug1: SSH2_MSG_KEX_ECDH_REPLY received\r\ndebug1: Server host key: ssh-ed25519 SHA256:NXFKpmmV4eHTo6AIqaBcbx0/M3GEz9i/hnvYuRsJo\r\ndebug3: put_host_port: [176.149.236.226]:442\r\ndebug3: put_host_port: [176.149.236.226]:442\r\ndebug3: record_hostkey: found key type ECDSA in file /home/foobar/.ssh/known_hosts:9\r\ndebug3: record_hostkey: found key type ED25519 in file /home/foobar/.ssh/known_hosts:12\r\ndebug3: load_hostkeys_file: loaded 2 keys from [176.149.236.226]:442\r\ndebug1: load_hostkeys: fopen /home/foobar/.ssh/known_hosts2: No such file or directory\r\ndebug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory\r\ndebug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory\r\ndebug1: Host \'[176.149.236.226]:442\' is known and matches the ED25519 host key.\r\ndebug1: Found key in /home/foobar/.ssh/known_hosts:12\r\ndebug3: send packet: type 21\r\ndebug1: ssh_packet_send2_wrapped: resetting send seqnr 3\r\ndebug2: ssh_set_newkeys: mode 1\r\ndebug1: rekey out after 134217728 blocks\r\ndebug1: SSH2_MSG_NEWKEYS sent\r\ndebug1: expecting SSH2_MSG_NEWKEYS\r\ndebug3: receive packet: type 21\r\ndebug1: ssh_packet_read_poll2: resetting read seqnr 3\r\ndebug1: SSH2_MSG_NEWKEYS received\r\ndebug2: ssh_set_newkeys: mode 0\r\ndebug1: rekey in after 134217728 blocks\r\ndebug3: ssh_get_authentication_socket_path: path \'/tmp/ssh-XXXXXXE5JBLx/agent.19957\'\r\ndebug1: get_agent_identities: bound agent to hostkey\r\ndebug1: get_agent_identities: agent returned 1 keys\r\ndebug1: Will attempt key: [email protected] ED25519 SHA256:SXxYIsmbKc2QZbd8ZkpOmimTLwpqiC5vy2I agent\r\ndebug1: Will attempt key: /home/foobar/.ssh/id_rsa \r\ndebug1: Will attempt key: /home/foobar/.ssh/id_ecdsa \r\ndebug1: Will attempt key: /home/foobar/.ssh/id_ecdsa_sk \r\ndebug1: Will attempt key: /home/foobar/.ssh/id_ed25519 \r\ndebug1: Will attempt key: /home/foobar/.ssh/id_ed25519_sk \r\ndebug1: Will attempt key: /home/foobar/.ssh/id_xmss \r\ndebug1: Will attempt key: /home/foobar/.ssh/id_dsa \r\ndebug2: pubkey_prepare: done\r\ndebug3: send packet: type 5\r\ndebug3: receive packet: type 7\r\ndebug1: SSH2_MSG_EXT_INFO received\r\ndebug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>\r\ndebug3: receive packet: type 6\r\ndebug2: service_accept: ssh-userauth\r\ndebug1: SSH2_MSG_SERVICE_ACCEPT received\r\ndebug3: send packet: type 50\r\ndebug3: receive packet: type 51\r\ndebug1: Authentications that can continue: publickey\r\ndebug3: start over, passed a different list publickey\r\ndebug3: preferred gssapi-with-mic,gssapi-keyex,hostbased,publickey\r\ndebug3: authmethod_lookup publickey\r\ndebug3: remaining preferred: ,gssapi-keyex,hostbased,publickey\r\ndebug3: authmethod_is_enabled publickey\r\ndebug1: Next authentication method: publickey\r\ndebug1: Offering public key: [email protected] ED25519 SHA256:SXxYIsambKc0Eg2QZbd8ZkpOpmipppqiC5vy2I agent\r\ndebug3: send packet: type 50\r\ndebug2: we sent a publickey packet, wait for reply\r\ndebug3: receive packet: type 60\r\ndebug1: Server accepts key: [email protected] ED25519 SHA256:SXxYIambKcEgOxf2QZd8ZkpOpmimpqiC5vy2I agent\r\ndebug3: sign_and_send_pubkey: using publickey with ED25519 SHA256:SXxYIsambc0EgOxfQZbd8ZmimTLwpqiC5uvy2I\r\ndebug3: sign_and_send_pubkey: signing using ssh-ed25519 SHA256:SXxYIsambKc0EgOxf2bd8ZkpOpimTLwpqiCviy2I\r\ndebug3: send packet: type 50\r\ndebug3: receive packet: type 52\r\ndebug1: Enabling compression at level 6.\r\nAuthenticated to 176.149.236.226 ([176.149.236.226]:442) using "publickey".\r\ndebug1: setting up multiplex master socket\r\ndebug3: muxserver_listen: temporary control path /home/foobar/.ansible/cp/707b007166.LaArg3vnlnisFkiE\r\ndebug2: fd 4 setting O_NONBLOCK\r\ndebug3: fd 4 is O_NONBLOCK\r\ndebug3: fd 4 is O_NONBLOCK\r\ndebug1: channel 0: new mux listener [/home/foobar/.ansible/cp/707b007166] (inactive timeout: 0)\r\ndebug3: muxserver_listen: mux listener channel 0 fd 4\r\ndebug2: fd 3 setting TCP_NODELAY\r\ndebug3: set_sock_tos: set socket 3 IP_TOS 0x08\r\ndebug1: control_persist_detach: backgrounding master process\r\ndebug2: control_persist_detach: background process is 35290\r\ndebug2: fd 4 setting O_NONBLOCK\r\ndebug1: forking to background\r\ndebug1: Entering interactive session.\r\ndebug1: pledge: id\r\ndebug3: client_repledge: enter\r\ndebug2: set_control_persist_exit_time: schedule exit in 60 seconds\r\ndebug1: multiplexing control connection\r\ndebug2: fd 5 setting O_NONBLOCK\r\ndebug3: fd 5 is O_NONBLOCK\r\ndebug1: channel 1: new mux-control [mux-control] (inactive timeout: 0)\r\ndebug3: channel_post_mux_listener: new mux channel 1 fd 5\r\ndebug3: mux_master_read_cb: channel 1: hello sent\r\ndebug2: set_control_persist_exit_time: cancel scheduled exit\r\ndebug3: mux_master_read_cb: channel 1 packet type 0x00000001 len 4\r\ndebug2: mux_master_process_hello: channel 1 client version 4\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_master_read_cb: channel 1 packet type 0x10000004 len 4\r\ndebug2: mux_master_process_alive_check: channel 1: alive check\r\ndebug3: mux_client_request_alive: done pid = 35292\r\ndebug3: mux_master_read_cb: channel 1 packet type 0x10000002 len 107\r\ndebug3: mux_client_request_session: session request sent\r\ndebug2: mux_master_process_new_session: channel 1: request tty 0, X 0, agent 0, subsys 0, term "xterm-256color", cmd "/bin/sh -c \'echo ~ansible && sleep 0\'", env 1\r\ndebug3: mux_master_process_new_session: got fds stdin 6, stdout 7, stderr 8\r\ndebug2: fd 7 setting O_NONBLOCK\r\ndebug2: fd 8 setting O_NONBLOCK\r\ndebug1: channel 2: new session [client-session] (inactive timeout: 0)\r\ndebug2: mux_master_process_new_session: channel_new: 2 linked to control channel 1\r\ndebug2: channel 2: send open\r\ndebug3: send packet: type 90\r\ndebug3: receive packet: type 80\r\ndebug1: client_input_global_request: rtype [email protected] want_reply 0\r\ndebug3: client_input_hostkeys: received RSA key SHA256:g7pOtO5TeitrdtmBVOY/diQ+UZRTuikmWCMQUnwZc\r\ndebug3: client_input_hostkeys: received ECDSA key SHA256:D/dxVTzGwyim9QXyN8D/iTxzbg+c7lJ/8NARIRN80\r\ndebug3: client_input_hostkeys: received ED25519 key SHA256:NXFKpm8mV4eTo6AI6qBcbx0/M3GEzi/hnuvYuRsJo\r\ndebug3: put_host_port: [176.149.236.226]:442\r\ndebug1: client_input_hostkeys: searching /home/foobar/.ssh/known_hosts for [176.149.236.226]:442 / (none)\r\ndebug3: hostkeys_foreach: reading file "/home/foobar/.ssh/known_hosts"\r\ndebug3: hostkeys_find: found ecdsa-sha2-nistp256 key at /home/foobar/.ssh/known_hosts:9\r\ndebug3: hostkeys_find: found ssh-ed25519 key at /home/foobar/.ssh/known_hosts:12\r\ndebug1: client_input_hostkeys: searching /home/foobar/.ssh/known_hosts2 for [176.149.236.226]:442 / (none)\r\ndebug1: client_input_hostkeys: hostkeys file /home/foobar/.ssh/known_hosts2 does not exist\r\ndebug3: client_input_hostkeys: 3 server keys: 1 new, 1 retained, 1 incomplete match. 0 to remove\r\ndebug3: client_input_hostkeys: asking server to prove ownership for 1 keys\r\ndebug3: send packet: type 80\r\ndebug3: receive packet: type 4\r\ndebug1: Remote: /home/ansible/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding\r\ndebug3: receive packet: type 4\r\ndebug1: Remote: /home/ansible/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding\r\ndebug3: receive packet: type 91\r\ndebug2: channel_input_open_confirmation: channel 2: callback start\r\ndebug2: client_session2_setup: id 2\r\ndebug1: Sending environment.\r\ndebug1: channel 2: setting env LANG = "en_US.UTF-8"\r\ndebug2: channel 2: request env confirm 0\r\ndebug3: send packet: type 98\r\ndebug1: Sending command: /bin/sh -c \'echo ~ansible && sleep 0\'\r\ndebug2: channel 2: request exec confirm 1\r\ndebug3: send packet: type 98\r\ndebug3: client_repledge: enter\r\ndebug3: mux_session_confirm: sending success reply\r\ndebug2: channel_input_open_confirmation: channel 2: callback done\r\ndebug2: channel 2: open confirm rwindow 0 rmax 32768\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: receive packet: type 81\r\ndebug1: client_global_hostkeys_prove_confirm: server used untrusted RSA signature algorithm ssh-rsa for key 0, disregarding\r\ndebug3: hostkeys_foreach: reading file "/home/foobar/.ssh/known_hosts"\r\ndebug3: host_delete: ECDSA key already at /home/foobar/.ssh/known_hosts:9\r\ndebug3: host_delete: ED25519 key already at /home/foobar/.ssh/known_hosts:12\r\ndebug1: update_known_hosts: known hosts file /home/foobar/.ssh/known_hosts2 does not exist\r\ndebug3: client_repledge: enter\r\ndebug2: channel 2: rcvd adjust 2097152\r\ndebug3: receive packet: type 99\r\ndebug2: channel_input_status_confirm: type 99 id 2\r\ndebug2: exec request accepted on channel 2\r\ndebug3: receive packet: type 96\r\ndebug2: channel 2: rcvd eof\r\ndebug2: channel 2: output open -> drain\r\ndebug2: channel 2: obuf empty\r\ndebug2: chan_shutdown_write: channel 2: (i0 o1 sock -1 wfd 7 efd 8 [write])\r\ndebug2: channel 2: output drain -> closed\r\ndebug3: receive packet: type 98\r\ndebug1: client_input_channel_req: channel 2 rtype exit-status reply 0\r\ndebug3: mux_exit_message: channel 2: exit message, exitval 0\r\ndebug3: receive packet: type 98\r\ndebug1: client_input_channel_req: channel 2 rtype [email protected] reply 0\r\ndebug2: channel 2: rcvd eow\r\ndebug2: chan_shutdown_read: channel 2: (i0 o3 sock -1 wfd 6 efd 8 [write])\r\ndebug2: channel 2: input open -> closed\r\ndebug3: receive packet: type 97\r\ndebug2: channel 2: rcvd close\r\ndebug3: channel 2: will not send data after close\r\ndebug2: channel 2: send close\r\ndebug3: send packet: type 97\r\ndebug2: channel 2: isSource: ansible/ansible