过去,我使用ansible 2.3.1.0,现在想使用ansible 2.6.3。
我现在想用apt安装一些软件包。因此,我必须获取列表,并且要将它们合并为一个。在ansible 2.3.1.0中,我只使用了以下内容:
apt_packages:
- "{{ packages_list1 + packages_list2 }}"
我收到以下错误:
Traceback (most recent call last):\r\n File \"/tmp/ansible_k0tmag/ansible_module_apt.py\", line 1128, in <module>\r\n main()\r\n File \"/tmp/ansible_k0tmag/ansible_module_apt.py\", line 1106, in main\r\n
allow_unauthenticated=allow_unauthenticated\r\n File \"/tmp/ansible_k0tmag/ansible_module_apt.py\", line 521, in install\r\n pkgspec = expand_pkgspec_from_fnmatches(m, pkgspec, cache)\r\n File \"/tmp/ansible_k0tmag/ansible_module_apt.py\", line 439, in expand_pkgspec_from_fnmatches\r\n
pkgname_pattern, version = package_split(pkgspec_pattern)\r\n File \"/tmp/ansible_k0tmag/ansible_module_apt.py\", line 312, in package_split\r\n
parts = pkgspec.split('=', 1)\r\nAttributeError: 'list' object has no attribute 'split'\r\n", "msg": "MODULE FAILURE", "rc": 1}
角色内容:
apt:
state: present
name: "{{ apt_packages }}"
force: yes
when: apt_packages is defined```
答案 0 :(得分:0)
使用apt_packages: "{{ packages_list1 + packages_list2 }}"
(不使用-
),它将起作用。
工作示例:
- hosts: localhost
gather_facts: no
vars:
pkgs1:
- perl
- python
pkgs2:
- vim
- tar
packages: "{{ pkgs1 + pkgs2 }}"
tasks:
- apt:
name: "{{ packages }}"
state: present