LoginSignup
2

More than 5 years have passed since last update.

ansibleで"could not locate file in lookup"って怒られる原因

Posted at

概要

ansibleを利用していると以下のようなエラーが出力されることがあります。

TASK: [common | set authorized key] *************************************
ok: [default] => (item={'name': 'hoge', 'key': u'ssh-rsa 公開鍵 whywaita@host'})

TASK: [common | configure application file] *****************************************
fatal: [default] => could not locate file in lookup: public_keys/id_rsa.pub

FATAL: all hosts have already failed -- aborting
roles/common/tasks/main.yml

- name: set authorized key
  authorized_key: user={{item.name}} key="{{item.key}}"
  with_items: authorized_keys
  tags: users

- name: configure application file
  template: src=hoge.conf.j2 dest=/etc/hoge.conf
  tags: hoge

roles/common/defaults/main.yml

authorized_keys:
  - name: admin
    key: "{{ lookup('file','public_keys/id_rsa.pub' ) }}"

今回だと公開鍵を指定するためにlookup関数を使って展開しているのですが、公開鍵を設置した後にアプリケーションのテンプレートを設置しようとすると何故か以前の公開鍵を参照しようとして転けます。

動作環境

  • OSX Yosemite
  • Ansible 1.8.2以降

原因

バグです。
ansible 1.8.2以降より確認されているバグで、既にIssueが立っています。
解決の為のPRも用意しているのですが、ansible v2のMilestoneに組み込まれているので、暫くは解決しそうにないです。

対処法

  • ansible 1.8.1を使う
  • lookup()関数を使わない
  • copy/template/file を使わない
  • ansible 2.0を試してみる

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2