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

3 Answers 3

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' }
2
  • Works like a charm! Sep 15, 2015 at 4:24
  • 2
    If you have issues with syntax/indentation, edit via atom + plugins: linter, ansible-linter, js-yaml-linter
    – Jonathan
    Jul 6, 2017 at 19:18
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' }
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .