Ansible command with_items

ansibledeploymentpostfix

In ansible 1.5.4 the following command worked flawlessly:

- 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

After upgrading to 1.9.1, the command fails with a 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}}"). error.

As {{ item }} is already quotes, I don't know what is wrong.

How can I get this command working again?

Best Answer

Have a look at https://github.com/ansible/ansible/issues/8260 for the details on why this change in behaviour was made (to prevent additional arguments being injected in the command module). The following format should work:

- 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