Failed to transfer file message

Here is my code.

---
- hosts: localhost
  become: true
  gather_facts: false

  vars:
    key_fn: "~/.ssh/id_rsa"

  tasks:
  - name: Check if file exists
    stat:
      path: "{{ key_fn }}"
    register: result

Here is the error I get:

TASK [Check if file exists] ****************************************************************************************************************************************************************
task path: /home/username/create_keys.yml:10
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: csswx-inf
<127.0.0.1> EXEC /bin/sh -c 'echo ~csswx-inf && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/username/.ansible/tmp `"&& mkdir "` echo /home/username/.ansible/tmp/ansible-tmp-1741121935.9362278-164236-271844918348868 `" && echo ansible-tmp-1741121935.9362278-164236-271844918348868="` echo /home/username/.ansible/tmp/ansible-tmp-1741121935.9362278-164236-271844918348868 `" ) && sleep 0'
Using module file /usr/lib/python3.9/site-packages/ansible/modules/stat.py
<127.0.0.1> PUT /home/username/.ansible/tmp/ansible-local-164232ueu2v7ga/tmp2lhlfh29 TO /home/username/.ansible/tmp/ansible-tmp-1741121935.9362278-164236-271844918348868/AnsiballZ_stat.py
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/username/.ansible/tmp/ansible-tmp-1741121935.9362278-164236-271844918348868/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "msg": "failed to transfer file to /home/username/.ansible/tmp/ansible-tmp-1741121935.9362278-164236-271844918348868/AnsiballZ_stat.py: [Errno 1] Operation not permitted: b'/home/username/.ansible/tmp/ansible-local-164232ueu2v7ga/tmp2lhlfh29'"
}

Why? The user “username” has these permissions:

drwx------. 3 username username   17 Mar  4 20:04 .ansible

Thanks.

csswx-inf != username ?

1 Like

Sorry was trying to anonymize things.

Here are the messages for a user called fred.

TASK [Check if file exists] ****************************************************************************************************************************************************************
task path: /home/fred/create_keys.yml:10
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: fred
<127.0.0.1> EXEC /bin/sh -c 'echo ~fred && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/fred/.ansible/tmp `"&& mkdir "` echo /home/fred/.ansible/tmp/ansible-tmp-1741180412.2887495-167410-17060392045159 `" && echo ansible-tmp-1741180412.2887495-167410-17060392045159="` echo /home/fred/.ansible/tmp/ansible-tmp-1741180412.2887495-167410-17060392045159 `" ) && sleep 0'
Using module file /usr/lib/python3.9/site-packages/ansible/modules/stat.py
<127.0.0.1> PUT /home/fred/.ansible/tmp/ansible-local-167406i299jc83/tmphl14ejvq TO /home/fred/.ansible/tmp/ansible-tmp-1741180412.2887495-167410-17060392045159/AnsiballZ_stat.py
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/fred/.ansible/tmp/ansible-tmp-1741180412.2887495-167410-17060392045159/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "msg": "failed to transfer file to /home/fred/.ansible/tmp/ansible-tmp-1741180412.2887495-167410-17060392045159/AnsiballZ_stat.py: [Errno 1] Operation not permitted: b'/home/fred/.ansible/tmp/ansible-local-167406i299jc83/tmphl14ejvq'"
}

I am running this playbook as “fred” without sudo.

Why the failure?

What is the ownership of /home/fred/.ansible and /home/fred/.ansible/tmp? All I can think of is that either might be root:root?