Creating a symlink with ansible and a list of variables

ansible

Brand new to ansible – I'm trying to symlink a bunch of files in a src directory to a destination.. Currently:

  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

I'm getting the error: fatal: [vmdev] => One or more undefined variables: 'item' is undefined

Can somebody point me in the right direction..? Cheers

Best Answer

Your indentation is wrong, with_items should be on the same level as file. This is what you want:

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' }