Ansible `authorized_key` copies the key to remote user but not working when trying to ssh
<p>I have the following task in my ansible playbook that adds my ssh public key for a remote user <code>pranjal</code> that was already created by a previous task.</p>

<pre><code>- authorized_key:
    user: pranjal
    key:  "{{ lookup('file', 'pranjal.pub') }}"
</code></pre>

<p>When I run the ansible playbook, it runs successfully. However when I try logging in to the server using: <code>ssh pranjal@&lt;server_ip&gt;</code></p>

<p>I get a <code>Permission denied (publickey)</code> error. </p>

<p>To be sure I logged into server from another user and double checked that key listed in <code>/home/pranjal/.ssh/authorized_keys</code> matches with my local public key that I am using to login. </p>

<p>The issue that I am guessing here could be a permissions issue and I understood the solution from a related <a href="https://stackoverflow.com/questions/6377009/adding-public-key-to-ssh-authorized-keys-does-not-log-me-in-automatically">question</a>.</p>

<p>But how do we change permissions of authorized_key from within the Ansible task  itself? (So that I don't have to separately log into the instance to modify permissions of .ssh/authorized_keys)</p>