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 module error when variable is provided #62055

MoreauGwenael opened this issue Sep 10, 2019 · 6 comments


Copy link

@MoreauGwenael MoreauGwenael commented Sep 10, 2019


While following the deprecation on the apt module about using a loop via squash_actions, I found that it is impossible to provide a variable using a list within the name variable (cf. example below if it is not clear).

  • Bug Report


ansible 2.8.4
  config file = /home/gwen/ansible/ansible.cfg
  configured module search path = [u'/home/gwen/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15+ (default, Jul  9 2019, 16:51:35) [GCC 7.4.0]
ANSIBLE_NOCOWS(/home/gwen/ansible/ansible.cfg) = True
DEFAULT_HOST_LIST(/home/gwen/ansible/ansible.cfg) = [u'/home/gwen/ansible/hosts']
DEFAULT_ROLES_PATH(/home/gwen/ansible/ansible.cfg) = [u'/home/gwen/ansible/roles']
HOST_KEY_CHECKING(/home/gwen/ansible/ansible.cfg) = False
RETRY_FILES_ENABLED(/home/gwen/ansible/ansible.cfg) = False

Ansible running on Ubuntu Bionic 18.04.3 LTS submodule for Windows.
Target is a Debian Stretch 9.9.


Reproduce only by using a variable in apt module name list :

- name: Install packages
      - pwgen
      - "{{ variable_name }}"
    update_cache: yes
    cache_valid_time: 600
    force_apt_get: yes
TASK [postgresql : Install packages] ***************************************************************************
ok: [test]
fatal: [test]: FAILED! => {
    "changed": false,
    "module_stderr": "OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\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_client_request_alive: done pid = 15673\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1568111658.95-225607490996439/\", line 114, in <module>\r\n    _ansiballz_main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1568111658.95-225607490996439/\", line 106, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1568111658.95-225607490996439/\", line 49, in invoke_module\r\n    imp.load_module('__main__', mod, module, MOD_DESC)\r\n  File \"/tmp/ansible_apt_payload_pdTjTv/\", line 1208, in <module>\r\n  File \"/tmp/ansible_apt_payload_pdTjTv/\", line 1186, in main\r\n  File \"/tmp/ansible_apt_payload_pdTjTv/\", line 610, in install\r\n  File \"/tmp/ansible_apt_payload_pdTjTv/\", line 528, in expand_pkgspec_from_fnmatches\r\n  File \"/tmp/ansible_apt_payload_pdTjTv/\", line 401, in package_split\r\nAttributeError: 'list' object has no attribute 'split'\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1

See extra-verbose (-vvvv) result here :


This comment has been minimized.

Copy link

@ansibot ansibot commented Sep 10, 2019

Files identified in the description:

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

click here for bot help


This comment has been minimized.

Copy link

@ansibot ansibot commented Sep 10, 2019


This comment has been minimized.

Copy link

@MoreauGwenael MoreauGwenael commented Sep 10, 2019

Additional note : This problem only occur when the variable is already a list, for example :

postgresql_packages :
  - postgresql-9.6
  - postgresql-client-9.6

If it is only one entry like following, it works perfectly :

postgresql_package : postgresql-9.6

This comment has been minimized.

Copy link

@bcoca bcoca commented Sep 10, 2019

So apt expects each item in the list to be a string, not a list, it does not flatten items into a single list

To avoid this you can do it several ways, this is one example:

name:  '{{ variable_name|union(['pwgen']) }}`

but it always requires you pass a 'list of strings' to the module.

I'm keeping this ticket open as this should be verified and give a useful error (i.e 'item is not a string') instead of a module failure.

@ansibot ansibot removed the needs_triage label Sep 10, 2019
@sivel sivel added easyfix P3 labels Sep 16, 2019

This comment has been minimized.

Copy link

@sivel sivel commented Sep 16, 2019

I think we likely just need to add elements='str' to the package argument in the argument spec.

Potentially mixed with #62027 and use str_strict instead of str


This comment has been minimized.

Copy link

@sblondon sblondon commented Oct 31, 2019

The bug has been fixed in commit 2108a2e

With this patch, it only raises a warning. However it cannot work properly, so it should be an error. str_strict is probably the right way to fix the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
6 participants
You can’t perform that action at this time.