From 40bcfd964600bcd34e478df3726e7d5d28e22b3c Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Tue, 5 Aug 2025 06:01:36 +1200 Subject: [PATCH] imgadm: command args as list rather than string (#10536) * imgadm: command args as list rather than string * add changelog frag * Update plugins/modules/imgadm.py Co-authored-by: Felix Fontein * Update plugins/modules/imgadm.py Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- changelogs/fragments/10536-imgadm-cmd-list.yml | 2 ++ plugins/modules/imgadm.py | 18 ++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/10536-imgadm-cmd-list.yml diff --git a/changelogs/fragments/10536-imgadm-cmd-list.yml b/changelogs/fragments/10536-imgadm-cmd-list.yml new file mode 100644 index 0000000000..0f22c774d8 --- /dev/null +++ b/changelogs/fragments/10536-imgadm-cmd-list.yml @@ -0,0 +1,2 @@ +minor_changes: + - imgadm - using safer mechanism to run external command (https://github.com/ansible-collections/community.general/pull/10536). diff --git a/plugins/modules/imgadm.py b/plugins/modules/imgadm.py index 1c29e8a94b..ef27508986 100644 --- a/plugins/modules/imgadm.py +++ b/plugins/modules/imgadm.py @@ -158,9 +158,9 @@ class Imgadm(object): def update_images(self): if self.uuid == '*': - cmd = '{0} update'.format(self.cmd) + cmd = [self.cmd, 'update'] else: - cmd = '{0} update {1}'.format(self.cmd, self.uuid) + cmd = [self.cmd, 'update', self.uuid] (rc, stdout, stderr) = self.module.run_command(cmd) @@ -177,13 +177,13 @@ class Imgadm(object): source = self.params['source'] imgtype = self.params['type'] - cmd = '{0} sources'.format(self.cmd) + cmd = [self.cmd, 'sources'] if force: - cmd += ' -f' + cmd = cmd + ['-f'] if self.present: - cmd = '{0} -a {1} -t {2}'.format(cmd, source, imgtype) + cmd = cmd + ['-a', source, '-t', imgtype] (rc, stdout, stderr) = self.module.run_command(cmd) if rc != 0: @@ -222,7 +222,7 @@ class Imgadm(object): if state == 'vacuumed': # Unconditionally pass '--force', otherwise we're prompted with 'y/N' - cmd = '{0} vacuum -f'.format(self.cmd) + cmd = [self.cmd, 'vacuum', '-f'] (rc, stdout, stderr) = self.module.run_command(cmd) @@ -234,8 +234,7 @@ class Imgadm(object): else: self.changed = True if self.present: - cmd = '{0} import -P {1} -q {2}'.format(self.cmd, pool, self.uuid) - + cmd = [self.cmd, 'import', '-P', pool, '-q'] + ([self.uuid] if self.uuid else []) (rc, stdout, stderr) = self.module.run_command(cmd) if rc != 0: @@ -253,8 +252,7 @@ class Imgadm(object): if re.match(regex, stdout.splitlines()[-1]): self.changed = True else: - cmd = '{0} delete -P {1} {2}'.format(self.cmd, pool, self.uuid) - + cmd = [self.cmd, 'delete', '-P', pool] + ([self.uuid] if self.uuid else []) (rc, stdout, stderr) = self.module.run_command(cmd) regex = '.*ImageNotInstalled.*'