0
name: copy public keys to users- for other environments authorized_key: user={{ item.username }} key="{{ lookup('file', '../files/{{ item.username }}.pub') }}" path='/home/{{ item.username }}/.ssh/authorized_keys' manage_dir=no with_items: - { username: 'xxxxxxxx' } - { username: 'xxxxxxxx' } - { username: 'xxxxxxxx' } 

Getting following error while running the above ansible code.

fatal: [xxxxxx.xxxx.com] => Failed to template user={{ item.username }} key="{{ lookup('file', '../files/{{ item.username }}.pub') }}": could not locate file in lookup: ../files/{{ item.username }}.pub 

1 Answer 1

0

Don't use nested Jinja2 expressions. Just use variable name as is:

{{ lookup('file', '../files/'+item.username+'.pub') }} 
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.