Ansible with_items、各項目を評価しない場合

Ansible with_items、各項目を評価しない場合

配列内のキーが設定されているかどうかに基づいて、配列内の異なるキーからファイルを作成しようとしています。

##################################################
#main site, same ftp user
- name: copy deploy keys private
  template: src=deploy_key dest=/root/.ssh/id_rsa-{{item.user}} owner=root group=root mode=0600
  with_items:
   - "{{joomla_websites + joomla_tls_websites + wordpress_websites + wordpress_h2_websites + phpbb_sites + symfony_websites + phpbb_sites}}"
  ignore_errors: true
  when: item.ftp_user is not defined
  tags:
    - sshd
    - newsite
#staging site, different ftp user, use same key
- name: copy deploy keys private
  template: src=deploy_key dest=/root/.ssh/id_rsa-{{item.ftp_user}} owner=root group=root mode=0600
  with_items:
   - "{{joomla_websites + joomla_tls_websites + wordpress_websites + wordpress_h2_websites + phpbb_sites + symfony_websites + phpbb_sites}}"
  ignore_errors: true
  when: item.ftp_user is defined
  tags:
    - sshd
    - newsite
##################################################

しかし、エラーが発生しています

fatal: [1.2.3.4]: FAILED! => {"failed": true, "msg": "The conditional check 'item.ftp_user is not defined' failed. The error was: error while evaluating conditional (item.ftp_user is not defined): 'item' is undefined\n\nThe error appears to have been in '/home/jochen/projects/automatem/ansible/roles/accounts/tasks/main.yml': line 14, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: copy deploy keys private, main site\n  ^ here\n"}

プレイブックのログメッセージに基づいて、Ansibleはアイテム配列全体を「when」に渡しています。私が望んでいるのは、各アイテムをループして、条件が真の場合に何かを実行することです。

どうすればこれを実現できるでしょうか?

答え1

with_items:
   - "{{joomla_web...}}”

1 つの項目を持つ配列を作成しました。代わりに、変数の結果を渡す必要があります。代わりにこれを試してください:

with_items: |
   "{{joomla_web...}}”

関連情報