community.general icon indicating copy to clipboard operation
community.general copied to clipboard

Intermittent Issues with Temporary Directory Creation and Connection Drops

Open Sohan-Opstree opened this issue 4 months ago • 7 comments

Summary

I am experiencing intermittent issues when using the Incus connection plugin in my Ansible playbook. The plugin sometimes fails to create a temporary directory and occasionally drops the connection mid-execution.

Issue Type

Bug Report

Component Name

plugins/connection/incus.py

Ansible Version

ansible [core 2.17.4]
  config file = /home/aerohub/Documents/compegon/incus_connection/ansible.cfg
  configured module search path = ['/home/aerohub/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/aerohub/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/aerohub/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/aerohub/.local/bin/ansible
  python version = 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
```

### Community.general Version

```
# /home/aerohub/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 9.4.0  

# /home/aerohub/.local/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 9.4.0  

# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 1.3.6  

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```


### OS / Environment

Ubuntu 24.04

### Steps to Reproduce

### Steps to Reproduce:
1. Use the following Ansible inventory configuration:
```
hosts:
  all:
    hosts:
      test-incus-connection:
        ansible_host: test-incus-connection
        ansible_connection: community.general.incus
        ansible_incus_remote: 130.12.23.2
        ansible_incus_project: default
        ansible_incus_executable: /bin/bash
    vars:
      ansible_user: root
```

2. Execute the following playbook:
```
---
- hosts: test-incus-connection
  become: no
  connection: community.general.incus
  gather_facts: no
  tasks:
    - name: Checking the directory
      ansible.builtin.command:
        cmd: ls -la
    
    - name: Updating cache & installing openssh-server package
      ansible.builtin.apt:
        name: openssh-server
        update_cache: true
        cache_valid_time: 3600

    - name: Creating Required directory
      ansible.builtin.file:
        path: /home/root/.ssh
        state: directory
        mode: '0755'

    - name: Copy SSH key
      ansible.builtin.copy:
        src: /home/aerohub/.ssh/id_ed25519.pub
        dest: /home/root/.ssh/authorized_keys
```

### Expected Results

The playbook should execute without errors, successfully creating the temporary directory and maintaining a stable connection throughout.

### Actual Results

```
aerohub@localhost:~/Documents/compegon/incus_connection$ ansible-playbook -i hosts playbook.yaml -vvv
ansible-playbook [core 2.17.4]
  config file = /home/aerohub/Documents/compegon/incus_connection/ansible.cfg
  configured module search path = ['/home/aerohub/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/aerohub/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/aerohub/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/aerohub/.local/bin/ansible-playbook
  python version = 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /home/aerohub/Documents/compegon/incus_connection/ansible.cfg as config file
host_list declined parsing /home/aerohub/Documents/compegon/incus_connection/hosts as it did not pass its verify_file() method
script declined parsing /home/aerohub/Documents/compegon/incus_connection/hosts as it did not pass its verify_file() method
auto declined parsing /home/aerohub/Documents/compegon/incus_connection/hosts as it did not pass its verify_file() method
Parsed /home/aerohub/Documents/compegon/incus_connection/hosts inventory source with yaml plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: playbook.yaml ************************************************************************************************************************************************************************************
1 plays in playbook.yaml

PLAY [test-incus-connection] *******************************************************************************************************************************************************************************

TASK [Checking the directory] ******************************************************************************************************************************************************************************
task path: /home/aerohub/Documents/compegon/incus_connection/playbook.yaml:7
<test-incus-connection> ESTABLISH Incus CONNECTION FOR USER: root
<test-incus-connection> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/.ansible-${USER}/tmp `"&& mkdir "` echo /tmp/.ansible-${USER}/tmp/ansible-tmp-1728020510.9072325-61273-110044330887728 `" && echo ansible-tmp-1728020510.9072325-61273-110044330887728="` echo /tmp/.ansible-${USER}/tmp/ansible-tmp-1728020510.9072325-61273-110044330887728 `" ) && sleep 0'
<test-incus-connection> Attempting python interpreter discovery
<test-incus-connection> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'python3.12'"'"'; command -v '"'"'python3.11'"'"'; command -v '"'"'python3.10'"'"'; command -v '"'"'python3.9'"'"'; command -v '"'"'python3.8'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python3'"'"'; echo ENDFOUND && sleep 0'
<test-incus-connection> EXEC /bin/sh -c '/usr/bin/python3.8 && sleep 0'
[WARNING]: Unhandled error in Python interpreter discovery for host test-incus-connection: Expecting value: line 1 column 1 (char 0)
<test-incus-connection> Interpreter discovery remote stderr:
Error: Only running operations can be connected
Using module file /home/aerohub/.local/lib/python3.10/site-packages/ansible/modules/command.py
<test-incus-connection> PUT /home/aerohub/.ansible/tmp/ansible-local-612705mq63pki/tmpudggjqjz TO /tmp/.ansible-root/tmp/ansible-tmp-1728020510.9072325-61273-110044330887728/AnsiballZ_command.py
<test-incus-connection> EXEC /bin/sh -c 'chmod u+x /tmp/.ansible-root/tmp/ansible-tmp-1728020510.9072325-61273-110044330887728/ /tmp/.ansible-root/tmp/ansible-tmp-1728020510.9072325-61273-110044330887728/AnsiballZ_command.py && sleep 0'
<test-incus-connection> EXEC /bin/sh -c '/usr/bin/python3.8 /tmp/.ansible-root/tmp/ansible-tmp-1728020510.9072325-61273-110044330887728/AnsiballZ_command.py && sleep 0'
<test-incus-connection> EXEC /bin/sh -c 'rm -f -r /tmp/.ansible-root/tmp/ansible-tmp-1728020510.9072325-61273-110044330887728/ > /dev/null 2>&1 && sleep 0'
[WARNING]: Error deleting remote temporary files (rc: 1, stderr: Error: Only running operations can be connected })
<test-incus-connection> EXEC /bin/sh -c 'rm -f -r /tmp/.ansible-root/tmp/ansible-tmp-1728020510.9072325-61273-110044330887728/ > /dev/null 2>&1 && sleep 0'
[WARNING]: Platform linux on host test-incus-connection is using the discovered Python interpreter at /usr/bin/python3.8, but future installation of another Python interpreter could change the meaning of
that path. See https://docs.ansible.com/ansible-core/2.17/reference_appendices/interpreter_discovery.html for more information.
changed: [test-incus-connection] => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3.8"
    },
    "changed": true,
    "cmd": [
        "ls",
        "-la"
    ],
    "delta": "0:00:00.002432",
    "end": "2024-10-04 11:12:41.131476",
    "invocation": {
        "module_args": {
            "_raw_params": "ls -la",
            "_uses_shell": false,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "expand_argument_vars": true,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true
        }
    },
    "msg": "",
    "rc": 0,
    "start": "2024-10-04 11:12:41.129044",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "total 36\ndrwx------  5 root root 4096 Oct  3 19:19 .\ndrwxr-xr-x 18 root root 4096 Oct  3 15:35 ..\n-rw-------  1 root root  309 Oct  3 19:13 .bash_history\n-rw-r--r--  1 root root 3106 Dec  5  2019 .bashrc\ndrwx------  2 root root 4096 Oct  3 19:13 .cache\n-rw-r--r--  1 root root  161 Dec  5  2019 .profile\ndrwxr-xr-x  2 root root 4096 Oct  3 19:12 .ssh\n-rw-------  1 root root  796 Oct  3 19:12 .viminfo\ndrwxr-xr-x  2 root root 4096 Oct  3 19:19 demo",
    "stdout_lines": [
        "total 36",
        "drwx------  5 root root 4096 Oct  3 19:19 .",
        "drwxr-xr-x 18 root root 4096 Oct  3 15:35 ..",
        "-rw-------  1 root root  309 Oct  3 19:13 .bash_history",
        "-rw-r--r--  1 root root 3106 Dec  5  2019 .bashrc",
        "drwx------  2 root root 4096 Oct  3 19:13 .cache",
        "-rw-r--r--  1 root root  161 Dec  5  2019 .profile",
        "drwxr-xr-x  2 root root 4096 Oct  3 19:12 .ssh",
        "-rw-------  1 root root  796 Oct  3 19:12 .viminfo",
        "drwxr-xr-x  2 root root 4096 Oct  3 19:19 demo"
    ]
}

TASK [Updating cache & installing openssh-server package] **************************************************************************************************************************************************
task path: /home/aerohub/Documents/compegon/incus_connection/playbook.yaml:11
<test-incus-connection> ESTABLISH Incus CONNECTION FOR USER: root
<test-incus-connection> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/.ansible-${USER}/tmp `"&& mkdir "` echo /tmp/.ansible-${USER}/tmp/ansible-tmp-1728020580.6446111-61607-17586347730847 `" && echo ansible-tmp-1728020580.6446111-61607-17586347730847="` echo /tmp/.ansible-${USER}/tmp/ansible-tmp-1728020580.6446111-61607-17586347730847 `" ) && sleep 0'
Using module file /home/aerohub/.local/lib/python3.10/site-packages/ansible/modules/apt.py
<test-incus-connection> PUT /home/aerohub/.ansible/tmp/ansible-local-612705mq63pki/tmpzqg0qylt TO /tmp/.ansible-root/tmp/ansible-tmp-1728020580.6446111-61607-17586347730847/AnsiballZ_apt.py
<test-incus-connection> EXEC /bin/sh -c 'chmod u+x /tmp/.ansible-root/tmp/ansible-tmp-1728020580.6446111-61607-17586347730847/ /tmp/.ansible-root/tmp/ansible-tmp-1728020580.6446111-61607-17586347730847/AnsiballZ_apt.py && sleep 0'
<test-incus-connection> EXEC /bin/sh -c 'rm -f -r /tmp/.ansible-root/tmp/ansible-tmp-1728020580.6446111-61607-17586347730847/ > /dev/null 2>&1 && sleep 0'
fatal: [test-incus-connection]: FAILED! => {
    "msg": "Failed to set execute bit on remote files (rc: 1, err: Error: Only running operations can be connected\n)"
}

PLAY RECAP *************************************************************************************************************************************************************************************************
test-incus-connection      : ok=1    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
```

### Sometime I see below Error:
```
aerohub@localhost:~/Documents/compegon/incus_connection$ ansible-playbook -i hosts playbook.yaml -vvv

ansible-playbook [core 2.17.4]
  config file = /home/aerohub/Documents/compegon/incus_connection/ansible.cfg
  configured module search path = ['/home/aerohub/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/aerohub/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/aerohub/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/aerohub/.local/bin/ansible-playbook
  python version = 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /home/aerohub/Documents/compegon/incus_connection/ansible.cfg as config file
host_list declined parsing /home/aerohub/Documents/compegon/incus_connection/hosts as it did not pass its verify_file() method
script declined parsing /home/aerohub/Documents/compegon/incus_connection/hosts as it did not pass its verify_file() method
auto declined parsing /home/aerohub/Documents/compegon/incus_connection/hosts as it did not pass its verify_file() method
Parsed /home/aerohub/Documents/compegon/incus_connection/hosts inventory source with yaml plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: playbook.yaml ************************************************************************************************************************************************************************************
1 plays in playbook.yaml

PLAY [test-incus-connection] *******************************************************************************************************************************************************************************

TASK [Checking the directory] ******************************************************************************************************************************************************************************
task path: /home/aerohub/Documents/compegon/incus_connection/playbook.yaml:7
<test-incus-connection> ESTABLISH Incus CONNECTION FOR USER: root
<test-incus-connection> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/.ansible-${USER}/tmp `"&& mkdir "` echo /tmp/.ansible-${USER}/tmp/ansible-tmp-1728020436.145059-60963-236863192956068 `" && echo ansible-tmp-1728020436.145059-60963-236863192956068="` echo /tmp/.ansible-${USER}/tmp/ansible-tmp-1728020436.145059-60963-236863192956068 `" ) && sleep 0'
fatal: [test-incus-connection]: UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo /tmp/.ansible-${USER}/tmp `\"&& mkdir \"` echo /tmp/.ansible-${USER}/tmp/ansible-tmp-1728020436.145059-60963-236863192956068 `\" && echo ansible-tmp-1728020436.145059-60963-236863192956068=\"` echo /tmp/.ansible-${USER}/tmp/ansible-tmp-1728020436.145059-60963-236863192956068 `\" ), exited with result 1",
    "unreachable": true
}

PLAY RECAP *************************************************************************************************************************************************************************************************
test-incus-connection      : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   
```

### incus monitor Logs
```


location: none
metadata:
  context:
    ip: 120.11.22.14:45914
    method: GET
    protocol: tls
    url: /1.0/operations/7cde5d8a-9fb7-4cf0-825b-19a7d54f6e01/websocket?secret=1d94391f520c40c154a3a3389e46d5834d7256d3d340dc59d4039e76e9c0cb4f
    username: 2f38e6baef3d3517e5b5fde6de6675139bafba219b3b24a6aa74873647d961d7
  level: debug
  message: Handling API request
timestamp: "2024-10-04T01:43:30.878793844-04:00"
type: logging


location: none
metadata:
  context:
    class: websocket
    description: Executing command
    operation: 7cde5d8a-9fb7-4cf0-825b-19a7d54f6e01
    project: default
  level: debug
  message: Connected to operation
timestamp: "2024-10-04T01:43:30.879029632-04:00"
type: logging


location: none
metadata:
  context:
    class: websocket
    description: Executing command
    err: Timed out waiting for websockets to connect
    operation: 7cde5d8a-9fb7-4cf0-825b-19a7d54f6e01
    project: default
  level: debug
  message: Failure for operation
timestamp: "2024-10-04T01:43:31.790933947-04:00"
type: logging


location: none
metadata:
  class: websocket
  created_at: "2024-10-04T01:43:26.780870759-04:00"
  description: Executing command
  err: Timed out waiting for websockets to connect
  id: 7cde5d8a-9fb7-4cf0-825b-19a7d54f6e01
  location: none
  may_cancel: false
  metadata:
    command:
    - /bin/sh
    - -c
    - /bin/sh -c 'rm -f -r /tmp/.ansible-root/tmp/ansible-tmp-1728020580.6446111-61607-17586347730847/
      > /dev/null 2>&1 && sleep 0'
    environment:
      HOME: /root
      LANG: C.UTF-8
      PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      TERM: xterm-256color
      USER: root
    fds:
      "0": 1ea3cf99ff87fc775eaa53f45f39c519eb246b75dae697f60bde419c690b6aa1
      "1": 1d94391f520c40c154a3a3389e46d5834d7256d3d340dc59d4039e76e9c0cb4f
      "2": 382c36b7687ea64e943b417abaf1e58f72a6449f7ffac7c968d68fc9d9432e8b
      control: 33d8da4fc7f3ef871f74cc99048249d1e5c4945fbea8c2c6f65d25ea52d4cda2
    interactive: false
  resources:
    instances:
    - /1.0/instances/test-incus-connection
  status: Failure
  status_code: 400
  updated_at: "2024-10-04T01:43:26.780870759-04:00"
project: default
timestamp: "2024-10-04T01:43:31.79134029-04:00"
type: operation


location: none
metadata:
  context:
    fingerprint: 2f38e6baef3d3517e5b5fde6de6675139bafba219b3b24a6aa74873647d961d7
    subject: CN=aerohub@sohan,O=linuxcontainers.org
  level: debug
  message: Matched trusted cert
timestamp: "2024-10-04T01:43:32.280946661-04:00"
type: logging


location: none
metadata:
  context:
    ip: 120.11.22.14:45928
    method: GET
    protocol: tls
    url: /1.0/operations/7cde5d8a-9fb7-4cf0-825b-19a7d54f6e01/websocket?secret=382c36b7687ea64e943b417abaf1e58f72a6449f7ffac7c968d68fc9d9432e8b
    username: 2f38e6baef3d3517e5b5fde6de6675139bafba219b3b24a6aa74873647d961d7
  level: debug
  message: Handling API request
timestamp: "2024-10-04T01:43:32.28103585-04:00"
type: logging


location: none
metadata:
  context:
    listener: 524246ac-9edd-48f4-8b79-e0ecb0479d3b
    local: 120.11.22.11:8443
    remote: 120.11.22.14:40740
  level: debug
  message: Event listener server handler stopped
timestamp: "2024-10-04T01:43:32.609439473-04:00"
type: logging



```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct

Sohan-Opstree avatar Oct 04 '24 05:10 Sohan-Opstree