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.pubPLAY RECAP ***********************************************************************************************************************
hqdc075.abc.com : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0