由于v2.11弃用而更改ansible循环

Ser*_*ult 21 linux ansible

我正在运行一个playbook,它定义了几个要安装的软件包apt:

    - name: Install utility packages common to all hosts
      apt:
        name: "{{ item }}"
        state: present
        autoclean: yes
      with_items:
        - aptitude
        - jq
        - curl
        - git-core
        - at
...
Run Code Online (Sandbox Code Playgroud)

我系统最近的一个ansible更新现在呈现有关上述剧本的消息:

[DEPRECATION WARNING]: Invoking "apt" only once while using a loop via squash_actions is deprecated. Instead of
 using a loop to supply multiple items and specifying `name: {{ item }}`, please use `name: [u'aptitude', 
u'jq', u'curl', u'git-core', u'at', u'heirloom-mailx', u'sudo-ldap', u'sysstat', u'vim', u'at', u'ntp', 
u'stunnel', u'sysstat', u'arping', u'net-tools', u'lshw', u'screen', u'tmux', u'lsscsi']` and remove the loop. 
Run Code Online (Sandbox Code Playgroud)

如果我正确理解这一点,Ansible现在想要这个包列表作为一个数组,留下这个:

name: [u'aptitude', u'jq', u'curl', u'git-core', u'at','heirloom-mailx', u'sudo-ldap', u'sysstat', u'vim', u'at', u'ntp',u'stunnel', u'sysstat', u'arping', u'net-tools', u'lshw', u'screen', u'tmux', u'lsscsi']
Run Code Online (Sandbox Code Playgroud)

有没有更好的办法?看起来我会在VIM中永远滚动,试图保持这一点.要么是这个,要么用自动换行处理包装的文字云.

Ign*_*lán 55

您可以使用YAML样式对数组进行编码,以使其更具可读性:

- name: Install utility packages common to all hosts
  apt:
    name:
      - aptitude
      - jq
      - curl
      - git-core
      - at
    state: present
    autoclean: yes
Run Code Online (Sandbox Code Playgroud)