why am i not able to access id_rsa.pub as another user?

I still keep geting this error

fatal: [localhost]: FAILED! => {“msg”: “An unhandled exception occurred while templating ‘{{ lookup(‘file’, ‘/home/rke/.ssh/id_rsa.pub’)}}’. Error was a <class ‘ansible.errors.AnsibleError’>, original message: 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/rke/.ssh/id_rsa.pub”}

The file does exist but the user running the task dont have access. So I used become: root
and become_method: sudo

but still dont work

simple permissions, can you 'cat '/home/rke/.ssh/id_rsa.pub` ? you
probably get same permissions error.

You either need to run ansible-playbook as a user with permissions
(rke, root?) or use a task to read the file while using privilege
escalation (become):

- slurp:
     path: , '/home/rke/.ssh/id_rsa.pub'
  become: yes
  delegate_to: localhost
  register: rke_pub_key

This is the equivalent of you doing `sudo cat
/home/rke/.ssh/id_rsa.pub' (lookups always run 'locally and are not
affected by become, which only affects the 'remote' side of a task).

thats what im trying to do

so does it mean I am unable to use elevate privileges using lookup?

simple permissions, can you 'cat '/home/rke/.ssh/id_rsa.pub` ? you
probably get same permissions error.

The $HOME/.ssh/ directory is normally restricted in its permissions to
permit the SSH private keys there to be used. It's partly why Ansible
has hooks to store private, and public, keys in the ansible vault
rather than merely pulling them from the local filesystem. The public
keys are not usually such an issue to publish as part of the playbook
or the ansible configuration itself. Is there any compelling reason
not to store such a reference public key in the playbook's
configuration files?

so does it mean I am unable to use elevate privileges using lookup?

exactly