17

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

williamsowen
  • 1,167
  • 3
  • 16
  • 25

3 Answers3

30

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' }
dtoubelis
  • 4,677
  • 1
  • 29
  • 32
7

I believe your syntax is wrong. Try this:

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' }
EEAA
  • 109,363
  • 18
  • 175
  • 245
4

If both source and destination link are named same then that should be even simpler:

- file:
    src: /drupal/drush/{{ item }}.aliases.drushrc.php
    dest: /home/vagrant/.drush/{{ item }}.aliases.drushrc.php
    state: link
  with_items:
    - new
    - vmdev
gertas
  • 1,077
  • 11
  • 12