创建带有ansible和变量列表的符号链接


17

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

有人可以指出我正确的方向吗?干杯

Answers:


30

您的缩进是错误的,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' }

奇迹般有效!
williamsowen

2
如果您在语法/缩进方面遇到问题,请通过atom +插件进行编辑:linter,ansible-linter,js-yaml-linter
Jonathan

7

我相信您的语法是错误的。尝试这个:

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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.