首页 > 解决方案 > 如何将列表与 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```


标签: ansible

解决方案


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

推荐阅读