From 8724c0deda4e77b1b6d528a59b980486ad616355 Mon Sep 17 00:00:00 2001 From: qw34ty <26134000+qw34ty@users.noreply.github.com> Date: Fri, 22 Feb 2019 09:24:07 +0000 Subject: [PATCH] lxd_container fix to check for snap package install unix.socket #34924 (#51541) * -added simple check to check snap unix.socket #34924 * fixed whitespacing around assignment * documented snap_url variable * documented snap_url variable * documented snap_var * updaed snap_var doc * version_added: to documenation * -updated check method to more reliable approach * -fixed whitespace missing in replace --- .../modules/cloud/lxd/lxd_container.py | 20 ++++++++++++++++++- lib/ansible/modules/cloud/lxd/lxd_profile.py | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/lxd/lxd_container.py b/lib/ansible/modules/cloud/lxd/lxd_container.py index a76231ca95..ce93b935bf 100644 --- a/lib/ansible/modules/cloud/lxd/lxd_container.py +++ b/lib/ansible/modules/cloud/lxd/lxd_container.py @@ -106,6 +106,12 @@ options: - The unix domain socket path or the https URL for the LXD server. required: false default: unix:/var/lib/lxd/unix.socket + snap_url: + description: + - The unix domain socket path when LXD is installed by snap package manager. + required: false + default: unix:/var/snap/lxd/common/lxd/unix.socket + version_added: '2.8' key_file: description: - The client certificate key file path. @@ -292,10 +298,18 @@ class LXDContainerManagement(object): self.force_stop = self.module.params['force_stop'] self.addresses = None - self.url = self.module.params['url'] self.key_file = self.module.params.get('key_file', None) self.cert_file = self.module.params.get('cert_file', None) self.debug = self.module._verbosity >= 4 + + try: + if os.path.exists(self.module.params['snap_url'].replace('unix:', '')): + self.url = self.module.params['snap_url'] + else: + self.url = self.module.params['url'] + except Exception as e: + self.module.fail_json(msg=e.msg) + try: self.client = LXDClient( self.url, key_file=self.key_file, cert_file=self.cert_file, @@ -583,6 +597,10 @@ def main(): type='str', default='unix:/var/lib/lxd/unix.socket' ), + snap_url=dict( + type='str', + default='unix:/var/snap/lxd/common/lxd/unix.socket' + ), key_file=dict( type='str', default='{0}/.config/lxc/client.key'.format(os.environ['HOME']) diff --git a/lib/ansible/modules/cloud/lxd/lxd_profile.py b/lib/ansible/modules/cloud/lxd/lxd_profile.py index d1bffddae1..d704f42ffa 100644 --- a/lib/ansible/modules/cloud/lxd/lxd_profile.py +++ b/lib/ansible/modules/cloud/lxd/lxd_profile.py @@ -67,6 +67,12 @@ options: - The unix domain socket path or the https URL for the LXD server. required: false default: unix:/var/lib/lxd/unix.socket + snap_url: + description: + - The unix domain socket path when LXD is installed by snap package manager. + required: false + default: unix:/var/snap/lxd/common/lxd/unix.socket + version_added: '2.8' key_file: description: - The client certificate key file path. @@ -199,10 +205,18 @@ class LXDProfileManagement(object): self.state = self.module.params['state'] self.new_name = self.module.params.get('new_name', None) - self.url = self.module.params['url'] self.key_file = self.module.params.get('key_file', None) self.cert_file = self.module.params.get('cert_file', None) self.debug = self.module._verbosity >= 4 + + try: + if os.path.exists(self.module.params['snap_url'].replace('unix:', '')): + self.url = self.module.params['snap_url'] + else: + self.url = self.module.params['url'] + except Exception as e: + self.module.fail_json(msg=e.msg) + try: self.client = LXDClient( self.url, key_file=self.key_file, cert_file=self.cert_file, @@ -352,6 +366,10 @@ def main(): type='str', default='unix:/var/lib/lxd/unix.socket' ), + snap_url=dict( + type='str', + default='unix:/var/snap/lxd/common/lxd/unix.socket' + ), key_file=dict( type='str', default='{0}/.config/lxc/client.key'.format(os.environ['HOME'])