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

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

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

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.