mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Added support for remote project in the LXD connection plugin (#1515)
This commit is contained in:
parent
0bd4b3cbc9
commit
6528aefcb5
1 changed files with 39 additions and 4 deletions
|
@ -14,7 +14,7 @@ DOCUMENTATION = '''
|
||||||
options:
|
options:
|
||||||
remote_addr:
|
remote_addr:
|
||||||
description:
|
description:
|
||||||
- Container identifier
|
- Container identifier.
|
||||||
default: inventory_hostname
|
default: inventory_hostname
|
||||||
vars:
|
vars:
|
||||||
- name: ansible_host
|
- name: ansible_host
|
||||||
|
@ -26,6 +26,19 @@ DOCUMENTATION = '''
|
||||||
vars:
|
vars:
|
||||||
- name: ansible_executable
|
- name: ansible_executable
|
||||||
- name: ansible_lxd_executable
|
- name: ansible_lxd_executable
|
||||||
|
remote:
|
||||||
|
description:
|
||||||
|
- Name of the LXD remote to use.
|
||||||
|
default: local
|
||||||
|
vars:
|
||||||
|
- name: ansible_lxd_remote
|
||||||
|
version_added: 2.0.0
|
||||||
|
project:
|
||||||
|
description:
|
||||||
|
- Name of the LXD project to use.
|
||||||
|
vars:
|
||||||
|
- name: ansible_lxd_project
|
||||||
|
version_added: 2.0.0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -70,7 +83,15 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
self._display.vvv(u"EXEC {0}".format(cmd), host=self._host)
|
self._display.vvv(u"EXEC {0}".format(cmd), host=self._host)
|
||||||
|
|
||||||
local_cmd = [self._lxc_cmd, "exec", self._host, "--", self._play_context.executable, "-c", cmd]
|
local_cmd = [self._lxc_cmd]
|
||||||
|
if self.get_option("project"):
|
||||||
|
local_cmd.extend(["--project", self.get_option("project")])
|
||||||
|
local_cmd.extend([
|
||||||
|
"exec",
|
||||||
|
"%s:%s" % (self.get_option("remote"), self._host),
|
||||||
|
"--",
|
||||||
|
self._play_context.executable, "-c", cmd
|
||||||
|
])
|
||||||
|
|
||||||
local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
|
local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
|
||||||
in_data = to_bytes(in_data, errors='surrogate_or_strict', nonstring='passthru')
|
in_data = to_bytes(in_data, errors='surrogate_or_strict', nonstring='passthru')
|
||||||
|
@ -98,7 +119,14 @@ class Connection(ConnectionBase):
|
||||||
if not os.path.isfile(to_bytes(in_path, errors='surrogate_or_strict')):
|
if not os.path.isfile(to_bytes(in_path, errors='surrogate_or_strict')):
|
||||||
raise AnsibleFileNotFound("input path is not a file: %s" % in_path)
|
raise AnsibleFileNotFound("input path is not a file: %s" % in_path)
|
||||||
|
|
||||||
local_cmd = [self._lxc_cmd, "file", "push", in_path, self._host + "/" + out_path]
|
local_cmd = [self._lxc_cmd]
|
||||||
|
if self.get_option("project"):
|
||||||
|
local_cmd.extend(["--project", self.get_option("project")])
|
||||||
|
local_cmd.extend([
|
||||||
|
"file", "push",
|
||||||
|
in_path,
|
||||||
|
"%s:%s/%s" % (self.get_option("remote"), self._host, out_path)
|
||||||
|
])
|
||||||
|
|
||||||
local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
|
local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
|
||||||
|
|
||||||
|
@ -111,7 +139,14 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
self._display.vvv(u"FETCH {0} TO {1}".format(in_path, out_path), host=self._host)
|
self._display.vvv(u"FETCH {0} TO {1}".format(in_path, out_path), host=self._host)
|
||||||
|
|
||||||
local_cmd = [self._lxc_cmd, "file", "pull", self._host + "/" + in_path, out_path]
|
local_cmd = [self._lxc_cmd]
|
||||||
|
if self.get_option("project"):
|
||||||
|
local_cmd.extend(["--project", self.get_option("project")])
|
||||||
|
local_cmd.extend([
|
||||||
|
"file", "pull",
|
||||||
|
"%s:%s/%s" % (self.get_option("remote"), self._host, in_path),
|
||||||
|
out_path
|
||||||
|
])
|
||||||
|
|
||||||
local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
|
local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue