We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
community.general.incus connection not working as inventory_hostname treated as litteral
### Summary

In my environment I am connecting to an incus server via a remote client on OSX.  Ansible, running on the OSX machine is utilizing roles, and gets the inventory_hostname from the filename under the host_vars directory.  I suspect this environment is causing inventory_hostname to be treated as a litteral.  A very similar bug was fixed community.general.lxd and be found here: https://github.com/ansible-collections/community.general/pull/4912

I have already implemented the solution and will submit a pull request.



### Issue Type

Bug Report

### Component Name

incus.py connection plugin

### Ansible Version

```console (paste below)
ansible [core 2.16.2]
  config file = /Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg
  configured module search path = ['/Users/travis/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/travis/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] (/opt/homebrew/opt/python@3.11/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general
# /Users/travis/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 8.2.0
```


### Configuration

```console (paste below)
$  ansible-config dump --only-changed
CONFIG_FILE() = /Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg
DEFAULT_HASH_BEHAVIOUR(/Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg) = merge
DEFAULT_HOST_LIST(/Users/travis/workspace//IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg) = ['/Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg) = ['/Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/inventory.ini']
EDITOR(env: EDITOR) = emacs
HOST_KEY_CHECKING(/Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg) = False

```


### OS / Environment

client: OSX
server: Ubuntu 22.04

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
# host_var file named IzumaMercury.yaml
ansible_connection: community.general.incus
ansible_user: root
ansible_become: no
ansible_incus_remote: IzumaExplorer
```


### Expected Results

ansible-playbook -i inventories/tests/moffett.yaml setup_izuma_networks_vm_controllers_workers.yml

PLAY [vm_controllers] ****************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************
ok: [IzumaMercury]


### Actual Results

```console (paste below)
ansible-playbook -i inventories/tests/moffett.yaml setup_izuma_networks_vm_controllers_workers.yml

PLAY [vm_controllers] ****************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************
[WARNING]: The "community.general.incus" connection plugin has an improperly configured remote target value, forcing
"inventory_hostname" templated value instead of the string
fatal: [IzumaMercury]: UNREACHABLE! => {"changed": false, "msg": "instance not found: inventory_hostname", "unreachable": true}
```


### Code of Conduct

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

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `plugins/connection/incus.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Based on lxd.py (c) 2016, Matt Clay <matt@mystile.com>
3 # (c) 2023, Stephane Graber <stgraber@stgraber.org>
4 # Copyright (c) 2023 Ansible Project
5 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
6 # SPDX-License-Identifier: GPL-3.0-or-later
7 
8 from __future__ import (absolute_import, division, print_function)
9 __metaclass__ = type
10 
11 DOCUMENTATION = """
12     author: Stéphane Graber (@stgraber)
13     name: incus
14     short_description: Run tasks in Incus instances via the Incus CLI.
15     description:
16         - Run commands or put/fetch files to an existing Incus instance using Incus CLI.
17     version_added: "8.2.0"
18     options:
19       remote_addr:
20         description:
21             - The instance identifier.
22         default: inventory_hostname
23         vars:
24             - name: ansible_host
25             - name: ansible_incus_host
26       executable:
27         description:
28             - The shell to use for execution inside the instance.
29         default: /bin/sh
30         vars:
31             - name: ansible_executable
32             - name: ansible_incus_executable
33       remote:
34         description:
35             - The name of the Incus remote to use (per C(incus remote list)).
36             - Remotes are used to access multiple servers from a single client.
37         default: local
38         vars:
39             - name: ansible_incus_remote
40       project:
41         description:
42             - The name of the Incus project to use (per C(incus project list)).
43             - Projects are used to divide the instances running on a server.
44         default: default
45         vars:
46             - name: ansible_incus_project
47 """
48 
49 import os
50 from subprocess import call, Popen, PIPE
51 
52 from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
53 from ansible.module_utils.common.process import get_bin_path
54 from ansible.module_utils._text import to_bytes, to_text
55 from ansible.plugins.connection import ConnectionBase
56 
57 
58 class Connection(ConnectionBase):
59     """ Incus based connections """
60 
61     transport = "incus"
62     has_pipelining = True
63     default_user = 'root'
64 
65     def __init__(self, play_context, new_stdin, *args, **kwargs):
66         super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
67 
68         self._incus_cmd = get_bin_path("incus")
69 
70         if not self._incus_cmd:
71             raise AnsibleError("incus command not found in PATH")
72 
73     def _connect(self):
74         """connect to Incus (nothing to do here) """
75         super(Connection, self)._connect()
76 
77         if not self._connected:
78             self._display.vvv(u"ESTABLISH Incus CONNECTION FOR USER: root",
79                               host=self._instance())
80             self._connected = True
81 
82     def _instance(self):
83         # Return only the leading part of the FQDN as the instance name
84         # as Incus instance names cannot be a FQDN.
85         return self.get_option('remote_addr').split(".")[0]
86 
87     def exec_command(self, cmd, in_data=None, sudoable=True):
88         """ execute a command on the Incus host """
89         super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
90 
91         self._display.vvv(u"EXEC {0}".format(cmd),
92                           host=self._instance())
93 
94         local_cmd = [
95             self._incus_cmd,
96             "--project", self.get_option("project"),
97             "exec",
98             "%s:%s" % (self.get_option("remote"), self._instance()),
99             "--",
100             self._play_context.executable, "-c", cmd]
101 
102         local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
103         in_data = to_bytes(in_data, errors='surrogate_or_strict', nonstring='passthru')
104 
105         process = Popen(local_cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
106         stdout, stderr = process.communicate(in_data)
107 
108         stdout = to_text(stdout)
109         stderr = to_text(stderr)
110 
111         if stderr == "Error: Instance is not running.\n":
112             raise AnsibleConnectionFailure("instance not running: %s" %
113                                            self._instance())
114 
115         if stderr == "Error: Instance not found\n":
116             raise AnsibleConnectionFailure("instance not found: %s" %
117                                            self._instance())
118 
119         return process.returncode, stdout, stderr
120 
121     def put_file(self, in_path, out_path):
122         """ put a file from local to Incus """
123         super(Connection, self).put_file(in_path, out_path)
124 
125         self._display.vvv(u"PUT {0} TO {1}".format(in_path, out_path),
126                           host=self._instance())
127 
128         if not os.path.isfile(to_bytes(in_path, errors='surrogate_or_strict')):
129             raise AnsibleFileNotFound("input path is not a file: %s" % in_path)
130 
131         local_cmd = [
132             self._incus_cmd,
133             "--project", self.get_option("project"),
134             "file", "push", "--quiet",
135             in_path,
136             "%s:%s/%s" % (self.get_option("remote"),
137                           self._instance(),
138                           out_path)]
139 
140         local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
141 
142         call(local_cmd)
143 
144     def fetch_file(self, in_path, out_path):
145         """ fetch a file from Incus to local """
146         super(Connection, self).fetch_file(in_path, out_path)
147 
148         self._display.vvv(u"FETCH {0} TO {1}".format(in_path, out_path),
149                           host=self._instance())
150 
151         local_cmd = [
152             self._incus_cmd,
153             "--project", self.get_option("project"),
154             "file", "pull", "--quiet",
155             "%s:%s/%s" % (self.get_option("remote"),
156                           self._instance(),
157                           in_path),
158             out_path]
159 
160         local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
161 
162         call(local_cmd)
163 
164     def close(self):
165         """ close the connection (nothing to do here) """
166         super(Connection, self).close()
167 
168         self._connected = False
169
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/plugins/connection/incus.py b/plugins/connection/incus.py
--- a/plugins/connection/incus.py
+++ b/plugins/connection/incus.py
@@ -21,6 +21,7 @@
             - The instance identifier.
         default: inventory_hostname
         vars:
+            - name: inventory_hostname
             - name: ansible_host
             - name: ansible_incus_host
       executable:

{"golden_diff": "diff --git a/plugins/connection/incus.py b/plugins/connection/incus.py\n--- a/plugins/connection/incus.py\n+++ b/plugins/connection/incus.py\n@@ -21,6 +21,7 @@\n             - The instance identifier.\n         default: inventory_hostname\n         vars:\n+            - name: inventory_hostname\n             - name: ansible_host\n             - name: ansible_incus_host\n       executable:\n", "issue": "community.general.incus connection not working as inventory_hostname treated as litteral\n### Summary\n\nIn my environment I am connecting to an incus server via a remote client on OSX.  Ansible, running on the OSX machine is utilizing roles, and gets the inventory_hostname from the filename under the host_vars directory.  I suspect this environment is causing inventory_hostname to be treated as a litteral.  A very similar bug was fixed community.general.lxd and be found here: https://github.com/ansible-collections/community.general/pull/4912\r\n\r\nI have already implemented the solution and will submit a pull request.\r\n\r\n\n\n### Issue Type\n\nBug Report\n\n### Component Name\n\nincus.py connection plugin\n\n### Ansible Version\n\n```console (paste below)\r\nansible [core 2.16.2]\r\n  config file = /Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg\r\n  configured module search path = ['/Users/travis/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']\r\n  ansible python module location = /opt/homebrew/lib/python3.11/site-packages/ansible\r\n  ansible collection location = /Users/travis/.ansible/collections:/usr/share/ansible/collections\r\n  executable location = /opt/homebrew/bin/ansible\r\n  python version = 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] (/opt/homebrew/opt/python@3.11/bin/python3.11)\r\n  jinja version = 3.1.2\r\n  libyaml = True\r\n\r\n```\r\n\n\n### Community.general Version\n\n```console (paste below)\r\n$ ansible-galaxy collection list community.general\r\n# /Users/travis/.ansible/collections/ansible_collections\r\nCollection        Version\r\n----------------- -------\r\ncommunity.general 8.2.0\r\n```\r\n\n\n### Configuration\n\n```console (paste below)\r\n$  ansible-config dump --only-changed\r\nCONFIG_FILE() = /Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg\r\nDEFAULT_HASH_BEHAVIOUR(/Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg) = merge\r\nDEFAULT_HOST_LIST(/Users/travis/workspace//IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg) = ['/Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg) = ['/Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/inventory.ini']\r\nEDITOR(env: EDITOR) = emacs\r\nHOST_KEY_CHECKING(/Users/travis/workspace/IZUMANETWORKS/siteinfra/Ansible/work/ansible.cfg) = False\r\n\r\n```\r\n\n\n### OS / Environment\n\nclient: OSX\r\nserver: Ubuntu 22.04\n\n### Steps to Reproduce\n\n<!--- Paste example playbooks or commands between quotes below -->\r\n```yaml (paste below)\r\n# host_var file named IzumaMercury.yaml\r\nansible_connection: community.general.incus\r\nansible_user: root\r\nansible_become: no\r\nansible_incus_remote: IzumaExplorer\r\n```\r\n\n\n### Expected Results\n\nansible-playbook -i inventories/tests/moffett.yaml setup_izuma_networks_vm_controllers_workers.yml\r\n\r\nPLAY [vm_controllers] ****************************************************************************************************\r\n\r\nTASK [Gathering Facts] ***************************************************************************************************\r\nok: [IzumaMercury]\r\n\n\n### Actual Results\n\n```console (paste below)\r\nansible-playbook -i inventories/tests/moffett.yaml setup_izuma_networks_vm_controllers_workers.yml\r\n\r\nPLAY [vm_controllers] ****************************************************************************************************\r\n\r\nTASK [Gathering Facts] ***************************************************************************************************\r\n[WARNING]: The \"community.general.incus\" connection plugin has an improperly configured remote target value, forcing\r\n\"inventory_hostname\" templated value instead of the string\r\nfatal: [IzumaMercury]: UNREACHABLE! => {\"changed\": false, \"msg\": \"instance not found: inventory_hostname\", \"unreachable\": true}\r\n```\r\n\n\n### Code of Conduct\n\n- [X] I agree to follow the Ansible Code of Conduct\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Based on lxd.py (c) 2016, Matt Clay <matt@mystile.com>\n# (c) 2023, Stephane Graber <stgraber@stgraber.org>\n# Copyright (c) 2023 Ansible Project\n# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import (absolute_import, division, print_function)\n__metaclass__ = type\n\nDOCUMENTATION = \"\"\"\n    author: St\u00e9phane Graber (@stgraber)\n    name: incus\n    short_description: Run tasks in Incus instances via the Incus CLI.\n    description:\n        - Run commands or put/fetch files to an existing Incus instance using Incus CLI.\n    version_added: \"8.2.0\"\n    options:\n      remote_addr:\n        description:\n            - The instance identifier.\n        default: inventory_hostname\n        vars:\n            - name: ansible_host\n            - name: ansible_incus_host\n      executable:\n        description:\n            - The shell to use for execution inside the instance.\n        default: /bin/sh\n        vars:\n            - name: ansible_executable\n            - name: ansible_incus_executable\n      remote:\n        description:\n            - The name of the Incus remote to use (per C(incus remote list)).\n            - Remotes are used to access multiple servers from a single client.\n        default: local\n        vars:\n            - name: ansible_incus_remote\n      project:\n        description:\n            - The name of the Incus project to use (per C(incus project list)).\n            - Projects are used to divide the instances running on a server.\n        default: default\n        vars:\n            - name: ansible_incus_project\n\"\"\"\n\nimport os\nfrom subprocess import call, Popen, PIPE\n\nfrom ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound\nfrom ansible.module_utils.common.process import get_bin_path\nfrom ansible.module_utils._text import to_bytes, to_text\nfrom ansible.plugins.connection import ConnectionBase\n\n\nclass Connection(ConnectionBase):\n    \"\"\" Incus based connections \"\"\"\n\n    transport = \"incus\"\n    has_pipelining = True\n    default_user = 'root'\n\n    def __init__(self, play_context, new_stdin, *args, **kwargs):\n        super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)\n\n        self._incus_cmd = get_bin_path(\"incus\")\n\n        if not self._incus_cmd:\n            raise AnsibleError(\"incus command not found in PATH\")\n\n    def _connect(self):\n        \"\"\"connect to Incus (nothing to do here) \"\"\"\n        super(Connection, self)._connect()\n\n        if not self._connected:\n            self._display.vvv(u\"ESTABLISH Incus CONNECTION FOR USER: root\",\n                              host=self._instance())\n            self._connected = True\n\n    def _instance(self):\n        # Return only the leading part of the FQDN as the instance name\n        # as Incus instance names cannot be a FQDN.\n        return self.get_option('remote_addr').split(\".\")[0]\n\n    def exec_command(self, cmd, in_data=None, sudoable=True):\n        \"\"\" execute a command on the Incus host \"\"\"\n        super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)\n\n        self._display.vvv(u\"EXEC {0}\".format(cmd),\n                          host=self._instance())\n\n        local_cmd = [\n            self._incus_cmd,\n            \"--project\", self.get_option(\"project\"),\n            \"exec\",\n            \"%s:%s\" % (self.get_option(\"remote\"), self._instance()),\n            \"--\",\n            self._play_context.executable, \"-c\", cmd]\n\n        local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]\n        in_data = to_bytes(in_data, errors='surrogate_or_strict', nonstring='passthru')\n\n        process = Popen(local_cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)\n        stdout, stderr = process.communicate(in_data)\n\n        stdout = to_text(stdout)\n        stderr = to_text(stderr)\n\n        if stderr == \"Error: Instance is not running.\\n\":\n            raise AnsibleConnectionFailure(\"instance not running: %s\" %\n                                           self._instance())\n\n        if stderr == \"Error: Instance not found\\n\":\n            raise AnsibleConnectionFailure(\"instance not found: %s\" %\n                                           self._instance())\n\n        return process.returncode, stdout, stderr\n\n    def put_file(self, in_path, out_path):\n        \"\"\" put a file from local to Incus \"\"\"\n        super(Connection, self).put_file(in_path, out_path)\n\n        self._display.vvv(u\"PUT {0} TO {1}\".format(in_path, out_path),\n                          host=self._instance())\n\n        if not os.path.isfile(to_bytes(in_path, errors='surrogate_or_strict')):\n            raise AnsibleFileNotFound(\"input path is not a file: %s\" % in_path)\n\n        local_cmd = [\n            self._incus_cmd,\n            \"--project\", self.get_option(\"project\"),\n            \"file\", \"push\", \"--quiet\",\n            in_path,\n            \"%s:%s/%s\" % (self.get_option(\"remote\"),\n                          self._instance(),\n                          out_path)]\n\n        local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]\n\n        call(local_cmd)\n\n    def fetch_file(self, in_path, out_path):\n        \"\"\" fetch a file from Incus to local \"\"\"\n        super(Connection, self).fetch_file(in_path, out_path)\n\n        self._display.vvv(u\"FETCH {0} TO {1}\".format(in_path, out_path),\n                          host=self._instance())\n\n        local_cmd = [\n            self._incus_cmd,\n            \"--project\", self.get_option(\"project\"),\n            \"file\", \"pull\", \"--quiet\",\n            \"%s:%s/%s\" % (self.get_option(\"remote\"),\n                          self._instance(),\n                          in_path),\n            out_path]\n\n        local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]\n\n        call(local_cmd)\n\n    def close(self):\n        \"\"\" close the connection (nothing to do here) \"\"\"\n        super(Connection, self).close()\n\n        self._connected = False\n", "path": "plugins/connection/incus.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Based on lxd.py (c) 2016, Matt Clay <matt@mystile.com>\n# (c) 2023, Stephane Graber <stgraber@stgraber.org>\n# Copyright (c) 2023 Ansible Project\n# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import (absolute_import, division, print_function)\n__metaclass__ = type\n\nDOCUMENTATION = \"\"\"\n    author: St\u00e9phane Graber (@stgraber)\n    name: incus\n    short_description: Run tasks in Incus instances via the Incus CLI.\n    description:\n        - Run commands or put/fetch files to an existing Incus instance using Incus CLI.\n    version_added: \"8.2.0\"\n    options:\n      remote_addr:\n        description:\n            - The instance identifier.\n        default: inventory_hostname\n        vars:\n            - name: inventory_hostname\n            - name: ansible_host\n            - name: ansible_incus_host\n      executable:\n        description:\n            - The shell to use for execution inside the instance.\n        default: /bin/sh\n        vars:\n            - name: ansible_executable\n            - name: ansible_incus_executable\n      remote:\n        description:\n            - The name of the Incus remote to use (per C(incus remote list)).\n            - Remotes are used to access multiple servers from a single client.\n        default: local\n        vars:\n            - name: ansible_incus_remote\n      project:\n        description:\n            - The name of the Incus project to use (per C(incus project list)).\n            - Projects are used to divide the instances running on a server.\n        default: default\n        vars:\n            - name: ansible_incus_project\n\"\"\"\n\nimport os\nfrom subprocess import call, Popen, PIPE\n\nfrom ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound\nfrom ansible.module_utils.common.process import get_bin_path\nfrom ansible.module_utils._text import to_bytes, to_text\nfrom ansible.plugins.connection import ConnectionBase\n\n\nclass Connection(ConnectionBase):\n    \"\"\" Incus based connections \"\"\"\n\n    transport = \"incus\"\n    has_pipelining = True\n    default_user = 'root'\n\n    def __init__(self, play_context, new_stdin, *args, **kwargs):\n        super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)\n\n        self._incus_cmd = get_bin_path(\"incus\")\n\n        if not self._incus_cmd:\n            raise AnsibleError(\"incus command not found in PATH\")\n\n    def _connect(self):\n        \"\"\"connect to Incus (nothing to do here) \"\"\"\n        super(Connection, self)._connect()\n\n        if not self._connected:\n            self._display.vvv(u\"ESTABLISH Incus CONNECTION FOR USER: root\",\n                              host=self._instance())\n            self._connected = True\n\n    def _instance(self):\n        # Return only the leading part of the FQDN as the instance name\n        # as Incus instance names cannot be a FQDN.\n        return self.get_option('remote_addr').split(\".\")[0]\n\n    def exec_command(self, cmd, in_data=None, sudoable=True):\n        \"\"\" execute a command on the Incus host \"\"\"\n        super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)\n\n        self._display.vvv(u\"EXEC {0}\".format(cmd),\n                          host=self._instance())\n\n        local_cmd = [\n            self._incus_cmd,\n            \"--project\", self.get_option(\"project\"),\n            \"exec\",\n            \"%s:%s\" % (self.get_option(\"remote\"), self._instance()),\n            \"--\",\n            self._play_context.executable, \"-c\", cmd]\n\n        local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]\n        in_data = to_bytes(in_data, errors='surrogate_or_strict', nonstring='passthru')\n\n        process = Popen(local_cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)\n        stdout, stderr = process.communicate(in_data)\n\n        stdout = to_text(stdout)\n        stderr = to_text(stderr)\n\n        if stderr == \"Error: Instance is not running.\\n\":\n            raise AnsibleConnectionFailure(\"instance not running: %s\" %\n                                           self._instance())\n\n        if stderr == \"Error: Instance not found\\n\":\n            raise AnsibleConnectionFailure(\"instance not found: %s\" %\n                                           self._instance())\n\n        return process.returncode, stdout, stderr\n\n    def put_file(self, in_path, out_path):\n        \"\"\" put a file from local to Incus \"\"\"\n        super(Connection, self).put_file(in_path, out_path)\n\n        self._display.vvv(u\"PUT {0} TO {1}\".format(in_path, out_path),\n                          host=self._instance())\n\n        if not os.path.isfile(to_bytes(in_path, errors='surrogate_or_strict')):\n            raise AnsibleFileNotFound(\"input path is not a file: %s\" % in_path)\n\n        local_cmd = [\n            self._incus_cmd,\n            \"--project\", self.get_option(\"project\"),\n            \"file\", \"push\", \"--quiet\",\n            in_path,\n            \"%s:%s/%s\" % (self.get_option(\"remote\"),\n                          self._instance(),\n                          out_path)]\n\n        local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]\n\n        call(local_cmd)\n\n    def fetch_file(self, in_path, out_path):\n        \"\"\" fetch a file from Incus to local \"\"\"\n        super(Connection, self).fetch_file(in_path, out_path)\n\n        self._display.vvv(u\"FETCH {0} TO {1}\".format(in_path, out_path),\n                          host=self._instance())\n\n        local_cmd = [\n            self._incus_cmd,\n            \"--project\", self.get_option(\"project\"),\n            \"file\", \"pull\", \"--quiet\",\n            \"%s:%s/%s\" % (self.get_option(\"remote\"),\n                          self._instance(),\n                          in_path),\n            out_path]\n\n        local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]\n\n        call(local_cmd)\n\n    def close(self):\n        \"\"\" close the connection (nothing to do here) \"\"\"\n        super(Connection, self).close()\n\n        self._connected = False\n", "path": "plugins/connection/incus.py"}]}