ansible 命令 with_items

Zul*_*kis 4 postfix deployment ansible

在 ansible 1.5.4 中,以下命令完美运行:

- name: Generate postfix dhparams
  command: "{{ item }}"
  with_items:
    - openssl gendh -out /etc/postfix/dh_512.pem -2 512 creates=/etc/postfix/dh_512.pem
    - openssl gendh -out /etc/postfix/dh_2048.pem -2 2048 creates=/etc/postfix/dh_2048.pem
  notify: Reload postfix
Run Code Online (Sandbox Code Playgroud)

升级到 1.9.1 后,命令失败并显示fatal: [127.0.0.1] => A variable inserted a new parameter into the module args. Be sure to quote variables if they contain equal signs (for example: "{{var}}").错误。

正如{{ item }}已经引用的那样,我不知道出了什么问题。

我怎样才能让这个命令再次工作?

mve*_*aes 5

查看https://github.com/ansible/ansible/issues/8260以了解有关为什么进行这种行为更改的详细信息(以防止在命令模块中注入额外的参数)。以下格式应该有效:

- name: Generate postfix dhparams
  command: "{{ item.command }} creates={{ item.file}}"
  with_items:
    - { command: 'openssl gendh -out /etc/postfix/dh_512.pem -2 512', file: '/etc/postfix/dh_512.pem' }
    - { command: 'openssl gendh -out /etc/postfix/dh_2048.pem -2 2048', file: '/etc/postfix/dh_2048.pem' }
  notify: Reload postfix
Run Code Online (Sandbox Code Playgroud)

  • 后者不是有效的 YAML 语法,这是 Ansible 在其剧本语言中使用的。如果以引号开始一个值,则需要以引号结束该值(和行)。尝试 https://yaml-online-parser.appspot.com/ 以获得有用的语法检查器。 (2认同)