diff --git a/changelogs/fragments/11192-solaris-zone-os-system.yml b/changelogs/fragments/11192-solaris-zone-os-system.yml new file mode 100644 index 0000000000..e4a131757f --- /dev/null +++ b/changelogs/fragments/11192-solaris-zone-os-system.yml @@ -0,0 +1,2 @@ +minor_changes: + - solaris_zone - execute external commands using Ansible construct (https://github.com/ansible-collections/community.general/pull/11192). diff --git a/plugins/modules/solaris_zone.py b/plugins/modules/solaris_zone.py index 78e1661e3e..09ccc6e508 100644 --- a/plugins/modules/solaris_zone.py +++ b/plugins/modules/solaris_zone.py @@ -309,12 +309,15 @@ class Zone: Wait until the zone's console login is running; once that's running, consider the zone booted. """ + zone_booted_re = re.compile(r"ttymon.*-d /dev/console") + cmd_ps = ["ps", "-z", self.name, "-o", "args"] + elapsed = 0 while True: if elapsed > self.timeout: self.module.fail_json(msg="timed out waiting for zone to boot") - rc = os.system(f'ps -z {self.name} -o args|grep "ttymon.*-d /dev/console" > /dev/null 2>/dev/null') - if rc == 0: + rc, out, err = self.module.run_command(cmd_ps, check_rc=False) + if any(zone_booted_re.match(x) for x in out.splitlines()): break time.sleep(10) elapsed += 10