对 ansible 来说很新 — — 我正在尝试将 src 目录中的一堆文件符号链接到目的地。目前:
file:
src: /drupal/drush/{{ item.path }}.aliases.drushrc.php
dest: /home/vagrant/.drush/{{ item.dest }}.aliases.drushrc.php
with_items:
- { path: 'new', dest: 'new' }
- { path: 'vmdev', dest: 'vmdev' }
state: link
我收到错误:fatal: [vmdev] => One or more undefined variables: 'item' is undefined
有人能给我指明正确的方向吗?谢谢
答案1
你的缩进是错误的,with_items
应该与 在同一级别file
。这是你想要的:
file:
src: "/drupal/drush/{{ item.path }}.aliases.drushrc.php"
dest: "/home/vagrant/.drush/{{ item.dest }}.aliases.drushrc.php"
state: link
with_items:
- { path: 'new', dest: 'new' }
- { path: 'vmdev', dest: 'vmdev' }
答案2
我认为你的语法是错误的。试试这个:
file: >
src=/drupal/drush/{{ item.path }}.aliases.drushrc.php
dest=/home/vagrant/.drush/{{ item.dest }}.aliases.drushrc.php
state=link
with_items:
- { path: 'new', dest: 'new' }
- { path: 'vmdev', dest: 'vmdev' }
答案3
如果源链接和目标链接的名称相同,那么应该更简单:
- file:
src: /drupal/drush/{{ item }}.aliases.drushrc.php
dest: /home/vagrant/.drush/{{ item }}.aliases.drushrc.php
state: link
with_items:
- new
- vmdev