Update container's packages in parallel?

I’m using this script to update all my LXD containers:

# Set full path to bins

# Get containers list
clist="$(${_lxc} list -c ns | ${_awk} '!/NAME/{ if ( $4 == "RUNNING" ) print $2}')"

function update_container() {

    echo "[Info] Updating $container"

    if ${_lxc} exec $container ${_apt} -- -v &> /dev/null
      echo "with apt"
      ${_lxc} exec $container ${_apt} -- update
      ${_lxc} exec $container ${_apt} -- -y full-upgrade
      ${_lxc} exec $container ${_apt} -- -y clean
      ${_lxc} exec $container ${_apt} -- -y autoclean

    elif ${_lxc} exec $container ${_paru} -- --version &> /dev/null
      echo "with paru"
      ${_lxc} exec --user 1000 $container -- ${_paru} -Syyu
      ${_lxc} exec $container ${_paru} -- -Sc --noconfirm

      echo "with pacman"
      ${_lxc} exec $container ${_pacman} -- -Syyu
      ${_lxc} exec $container ${_pacman} -- -Sc --noconfirm

for c in $clist
  update_container $c

but of course it updates the containers one at a time, which can be slow. Is it possible to run something like this on all my LXD containers in parallel to update all at once? I know the Paru one will need some work, since it needs sudo input, but I think I can work around that somehow (or just disable it for now).

Ansible can be helpful here, there is an available connection plugin for LXD : Linux Containers - LXD - Third-party integrations

It doesn’t use SSH, it’s much like what you are doing here with your scripts.

Finally, there is also a video from @stgraber available on YT on this topic : LXD and Ansible - YouTube

you can simply rewrite script to use parallel (GNU Parallel - GNU Project - Free Software Foundation)