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