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
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.