ansible - 如何将列表与 ansible 2.6.3 合并
问题描述
过去我使用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```
解决方案
有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
推荐阅读
- sql - 如何更新用户从存储过程的下拉列表中选择的唯一字段?
- asp.net - 我可以在不安装 SQL Server 的情况下访问数据库吗
- wordpress - 以自定义帖子类型保存按此帖子 Wordpress 5.3
- generics - Kotlin 泛型使用 when 检查类类型
- windows - 如何在 Windows 10 中打开或读取复制的系统注册表文件而不导入
- mysql - Typeorm如何获取关系的关系
- grafana - Grafana 中简单查询的空数据。表工作正常
- python - 其他行的日期时间的 Pandas 数据框条件
- umbraco - Umbraco 外部会员提供商
- angular - 如何避免循环依赖(特殊情况)