使用Ansible2,在`with_items`循环中使用`lookup(' file',item)`的正确方法是什么?

时间:2016-08-01 03:35:19

标签: ansible ansible-2.x

我使用的是ansible 2.1.0。我正在查看此页面http://ryaneschinger.com/blog/securing-a-server-with-ansible/并运行以下部分的剧本:

- name: Add authorized keys for deploy user
  authorized_key: user={{ username }}
                  key="{{ lookup('file', item) }}"
  with_items: public_keys

当我运行时,我得到[DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full variable syntax ('{{public_keys}}').有什么不被弃用的方法呢?

1 个答案:

答案 0 :(得分:3)

正如documentation中所述,with_循环中的裸变量应改为使用“{{var}}”语法,这有助于消除歧义。

所以,它只是告诉你改变这个:

with_items: public_keys

到此:

with_items: "{{ public_keys }}"