could not locate file in lookup to deploy authorized_keys

1,949 views
Skip to first unread message

Chang Eric

unread,
Dec 30, 2019, 8:04:50 PM12/30/19
to Ansible Project
I have a task like this

- name: test
  tags: key
  authorized_key:
    user: "{{ item }}"
    state: present
    key: "{{lookup('file', '/home/{{ item }}/.ssh/id_rsa.pub')}}"                                                                 
  with_items:
    - changch
  become_user: "{{ item }}"


 I'm sure the id_rsa.pub exists in local ansible controller (actually, the file exists on both node )

[minion@hqs009 ansiblecontrol]$ sudo ls -lart /home/changch/.ssh/id_rsa.pub
-rw------- 1 changch root 757 Mar 23  2018 /home/changch/.ssh/id_rsa.pub
[minion@hqs009 ansiblecontrol]$ 

but there are some error messages like this
 
task path: /home/mini/D/ansiblecontrol/roles/bootstrap-1804/tasks/main.yml:113
Tuesday 31 December 2019  09:01:40 +0800 (0:00:04.004)       0:00:04.141 ****** 
[WARNING]: Unable to find '/home/changch/.ssh/id_rsa.pub' in expected paths (use -vvvvv to see paths)
File lookup using None as file
fatal: [hqdc075.abc.com]: FAILED! => {}
MSG:
An unhandled exception occurred while running the lookup plugin 'file'. Error was a <class 'ansible.errors.AnsibleError'>, original message: could not locate file in lookup: /home/changch/.ssh/id_rsa.pub

PLAY RECAP ***********************************************************************************************************************
hqdc075.abc.com    : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0 



Kai Stian Olstad

unread,
Dec 31, 2019, 6:09:50 AM12/31/19
to ansible...@googlegroups.com
On 31.12.2019 02:04, Chang Eric wrote:
> I have a task like this
>
> - name: test
>> tags: key
>> authorized_key:
>> user: "{{ item }}"
>> state: present
>> key: "{{lookup('file', '/home/{{ item }}/.ssh/id_rsa.pub')}}"
>>
>> with_items:
>> - changch
>> become_user: "{{ item }}"
>
>
>
> I'm sure the id_rsa.pub exists in local ansible controller (actually,
> the
> file exists on both node )
>
> [minion@hqs009 ansiblecontrol]$ sudo ls -lart
> /home/changch/.ssh/id_rsa.pub
>> -rw------- 1 changch root 757 Mar 23 2018
>> /home/changch/.ssh/id_rsa.pub
>> [minion@hqs009 ansiblecontrol]$

If you are sure the file exist on localhost then it's much likely a
permission issue.

With your sudo command you are checking with root user, root have all
permission, you need to check with the same user as the playbook.

sudo -u changch cat /home/changch/.ssh/id_rsa.pub

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages