Hi there,
I’m attempting to configure a variable lookup to a public key file, and am running into some trouble. What confuses me is that the variable substitution works fine in a debug statement, but then blows up in the lookup statement for assigning authorized key values. Here’s the general idea;
provisioning/git.yml (playbook):
sudo: true
roles:
- { role: git, git_users: [ ‘me’ ] }
provisioning/roles/git/tasks/main.yml:
with_items: git_users
- authorized_key: user=git key={{ lookup(‘file’, ‘…/…/users/files/’ + item + ‘.pub’) }}
with_items: git_users
When I run ansible against the git.yml playbook, I end up with the following:
TASK: [debug msg=…/…/users/files/.pub] **************************************
ok: [dev-build-c.oedev.us] => (item=me) => {“item”: “me”, “msg”: “…/…/users/files/me.pub”}
ERROR: blah/blah/blah/provisioning/roles/users/files/.pub does not exist
I’m really struggling with understanding what I am missing in terms of looping and the lookup functionality. We’re using lookups elsewhere with dynamically constructed paths for passwords, and it seems to work like I’d expect. But when I introduce a loop, it falls apart.
Thanks for any pointers to relieve me of my ignorance!
Chris
I don’t see this as blowing up, I see this as reporting an error that it couldn’t find the file.
Help me understand why the file is not where you think it is?
In the debug and error lines:
ok: [dev-build-c.oedev.us] => (item=me) => {“item”: “me”, “msg”: “…/…/users/files/me.pub”}
ERROR: blah/blah/blah/provisioning/roles/users/files/.pub does not exist
The item it’s supposed to be supplying is “me”, so I would expect the path it derives for the lookup to be “…/…/users/files/me.pub”, but instead it’s hitting the lookup as “…/…/users/files/.pub”, and the portion where the replacement would occur is blank (hence it’s “.pub” and not “me.pub”. Does that make sense?
I’ve managed to create a test case for this (these files fall under an ansible-test directory):
## looptest.yml
connection: local
vars:
mylist:
roles:
## roles/looptest/tasks/main.yml
with_items: mylist
-
debug: msg=“{{ lookup(‘file’, ‘…/…/filerole/files/item1.txt’) }}”
-
debug: msg=“{{ lookup(‘file’, ‘…/…/filerole/files/’ + item + ‘.txt’) }}”
with_items: mylist
## roles/filerole/files/item1.txt
Testing!
This produces the following output on Ansible 1.3.2, Python 2.7.5 (Homebrew), Mac OSX 10.8.5, using the command ansible-playbook looptest.yml -i “127.0.0.1,”:
PLAY [127.0.0.1] **************************************************************
GATHERING FACTS ***************************************************************
ok: [127.0.0.1]
TASK: [debug msg=“”] **********************************************************
ok: [127.0.0.1] => (item=item1) => {“item”: “item1”, “msg”: “item1”}
TASK: [debug msg=“Testing”] ***************************************************
ok: [127.0.0.1] => {“item”: “”, “msg”: “Testing”}
ERROR: /blah/blah/blah/ansible-test/roles/filerole/files/.txt does not exist
I would expect that ERROR line to be searching for /blah/blah/blah/ansible-test/roles/filerole/files/item1.txt, not just a “.txt” file with no filename portion.
Does that help at all?
Chris
Please file a github ticket.
Thanks!
You bet, ticket 4549 created!